module Doorkeeper

def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)

def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
  OAuth::Token.authenticate(request, *methods)
end

def self.configuration

def self.configuration
  @config || (raise MissingConfiguration)
end

def self.configure(&block)

def self.configure(&block)
  @config = Config::Builder.new(&block).build
  setup_orm_adapter
  setup_orm_models
  setup_application_owner if @config.enable_application_owner?
  @config
end

def self.gem_version

def self.gem_version
  Gem::Version.new VERSION::STRING
end

def self.setup_application_owner

def self.setup_application_owner
  @orm_adapter.initialize_application_owner!
end

def self.setup_orm_adapter

def self.setup_orm_adapter
  @orm_adapter = "doorkeeper/orm/#{configuration.orm}".classify.constantize
rescue NameError => e
  raise e, "ORM adapter not found (#{configuration.orm})", <<-ERROR_MSG.strip_heredoc
    [doorkeeper] ORM adapter not found (#{configuration.orm}), or there was an error
    trying to load it.
    You probably need to add the related gem for this adapter to work with
    doorkeeper.
  ERROR_MSG
end

def self.setup_orm_models

def self.setup_orm_models
  @orm_adapter.initialize_models!
end