Module: Authlogic::Session::ActiveRecordTrickery

Included in:
Base
Defined in:
lib/authlogic/session/active_record_trickery.rb

Overview

Authlogic looks like ActiveRecord, sounds like ActiveRecord, but its not ActiveRecord. That’s the goal here. This is useful for the various rails helper methods such as form_for, error_messages_for, or any method that expects an ActiveRecord object. The point is to disguise the object as an ActiveRecord object so we can take advantage of the many ActiveRecord tools.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/authlogic/session/active_record_trickery.rb', line 8

def self.included(klass)
  klass.extend ActiveModel::Naming
  klass.extend ActiveModel::Translation

  # Support ActiveModel::Name#name for Rails versions before 4.0.
  if !klass.model_name.respond_to?(:name)
    ActiveModel::Name.module_eval do
      alias_method :name, :to_s
    end
  end

  klass.extend ClassMethods
  klass.send(:include, InstanceMethods)
end