Commit 38a6dda4 by liyijie

Refector the include method

parent 6fabc153
require "rails_api_authentication/version"
require "rails_api_authentication/configuration"
require "rails_api_authentication/auth_action"
require "rails_api_authentication/auth_session"
require "rails_api_authentication/auth_token"
require "rails_api_authentication/authable"
require "rails_api_authentication/acts_as_authenticationable"
require "rails_api_authentication/acts_as_authentication_handler"
module RailsApiAuthentication
extend Configuration
private
def self.ensure_models_can_act_as_token_authenticatables model_adapters
model_adapters.each do |model_adapter|
model_adapter.base_class.send :extend, RailsApiAuthentication::ActsAsAuthenticationable
end
end
def self.ensure_controllers_can_act_as_token_authentication_handlers controller_adapters
controller_adapters.each do |controller_adapter|
controller_adapter.base_class.send :extend, RailsApiAuthentication::ActsAsAuthenticationHandler
end
end
available_model_adapters = load_available_adapters RailsApiAuthentication.model_adapters
ensure_models_can_act_as_token_authenticatables available_model_adapters
available_controller_adapters = load_available_adapters RailsApiAuthentication.controller_adapters
ensure_controllers_can_act_as_token_authentication_handlers available_controller_adapters
end
module RailsApiAuthentication
module ActsAsAuthenticationHandler
def acts_as_auth_action(klass_sym, options={})
include RailsApiAuthentication::AuthAction
auth_action klass_sym, options
end
def acts_as_auth_session(klass_sym)
include RailsApiAuthentication::AuthSession
auth_session klass_sym
end
end
end
module RailsApiAuthentication
module ActsAsAuthenticationable
def acts_as_authentication(params = {})
include RailsApiAuthentication::Authable
auth_for params
end
end
end
module RailsApiAuthentication
module Configuration
mattr_accessor :controller_adapters
mattr_accessor :model_adapters
@@model_adapters = ['active_record', 'mongoid']
@@adapters_dependencies = { 'active_record' => 'ActiveRecord::Base',
'mongoid' => 'Mongoid::Document',
'rails' => 'ActionController::Base',
'rails_api' => 'ActionController::API',
'rails_metal' => 'ActionController::Metal' }
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment