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.check_requirements

def self.check_requirements
  @orm_adapter.check_requirements!(configuration)
end

def self.configuration

def self.configuration
  @config || (fail MissingConfiguration.new)
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?
  check_requirements
end

def self.configured?

def self.configured?
  @config.present?
end

def self.database_installed?

def self.database_installed?
  [AccessToken, AccessGrant, Application].all? { |model| model.table_exists? }
end

def self.installed?

def self.installed?
  configured? && database_installed?
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
  fail e, "ORM adapter not found (#{configuration.orm})", <<-ERROR_MSG.squish
oorkeeper] ORM adapter not found (#{configuration.orm}), or there was an error
ying to load it.
u probably need to add the related gem for this adapter to work with
orkeeper.
    ERROR_MSG
end

def self.setup_orm_models

def self.setup_orm_models
  @orm_adapter.initialize_models!
end