Module: Sorcery::Model
- Defined in:
- lib/sorcery/model.rb,
lib/sorcery.rb,
lib/sorcery/model/temporary_token.rb,
lib/sorcery/model/submodules/oauth.rb,
lib/sorcery/model/submodules/remember_me.rb,
lib/sorcery/model/submodules/reset_password.rb,
lib/sorcery/model/submodules/user_activation.rb,
lib/sorcery/model/submodules/activity_logging.rb,
lib/sorcery/model/submodules/brute_force_protection.rb
Overview
This module handles all plugin operations which are related to the Model layer in the MVC pattern. It should be included into the ORM base class. In the case of Rails this is usually ActiveRecord (actually, in that case, the plugin does this automatically).
When included it defines a single method: ‘activate_sorcery!’ which when called adds the other capabilities to the class. This method is also the place to configure the plugin in the Model layer.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, Submodules, TemporaryToken Classes: Config
Class Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sorcery/model.rb', line 9 def self.included(klass) klass.class_eval do class << self def activate_sorcery! @sorcery_config = Config.new self.class_eval do extend ClassMethods # included here, before submodules, so they can be overriden by them. include InstanceMethods ::Sorcery::Controller::Config.user_class = self @sorcery_config.submodules = ::Sorcery::Controller::Config.submodules @sorcery_config.submodules.each do |mod| begin include Submodules.const_get(mod.to_s.split("_").map {|p| p.capitalize}.join("")) rescue NameError # don't stop on a missing submodule. end end end yield @sorcery_config if block_given? self.class_eval do attr_accessor @sorcery_config.password_attribute_name attr_protected @sorcery_config.crypted_password_attribute_name, @sorcery_config.salt_attribute_name before_save :encrypt_password, :if => Proc.new { |record| record.send(sorcery_config.password_attribute_name).present? } after_save :clear_virtual_password, :if => Proc.new { |record| record.send(sorcery_config.password_attribute_name).present? } end @sorcery_config.after_config.each { |c| send(c) } end end end end |