Module: ActsAsBlamable::ClassMethods

Defined in:
lib/acts_as_blamable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_blamable(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/acts_as_blamable.rb', line 7

def acts_as_blamable(options={})
  class_variable_set :@@bl_conf, { :current_user_method => :current_user, :class_name => 'User', :creator_foreign_key => :created_by, :updater_foreign_key => :updated_by }
  bl_conf.update(options) if options.is_a? Hash
  
  class_eval do
    include ActsAsBlamable::InstanceMethods
    
    belongs_to :creator, :foreign_key => bl_conf[:creator_foreign_key], :class_name => bl_conf[:class_name]
    belongs_to :updater, :foreign_key => bl_conf[:updater_foreign_key], :class_name => bl_conf[:class_name]
    
    before_create :save_creator
    before_update :save_updater
  end
end

#bl_confObject



22
23
24
# File 'lib/acts_as_blamable.rb', line 22

def bl_conf
  class_variable_get :@@bl_conf
end