Module: Cure

Defined in:
lib/rubicure/cure.rb,
lib/rubicure/cure_cosmo.rb

Defined Under Namespace

Modules: CosmoExt

Class Method Summary collapse

Class Method Details

.define_turnover_methods(target, original_human_name, another_human_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubicure/cure.rb', line 8

def self.define_turnover_methods(target, original_human_name, another_human_name)
  target.instance_variable_set(:@__original_human_name, original_human_name)
  target.instance_variable_set(:@__another_human_name,  another_human_name)

  def target.!
    humanize!
    @another_human_name ||= @__another_human_name

    self[:human_name], @another_human_name = @another_human_name, self[:human_name]

    self
  end

  def target.rollback
    self[:human_name]   = @__original_human_name
    @another_human_name = @__another_human_name
    self
  end
end