Class: Dunlop::AttributeChangesTracking::LastChanged

Inherits:
Object
  • Object
show all
Defined in:
app/models/dunlop/attribute_changes_tracking.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ LastChanged

Returns a new instance of LastChanged.



40
41
42
# File 'app/models/dunlop/attribute_changes_tracking.rb', line 40

def initialize(target)
  @target = target
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



44
45
46
47
# File 'app/models/dunlop/attribute_changes_tracking.rb', line 44

def method_missing(m, *args)
  raise "#{target.class.name} has no attribute #{m}" unless target.has_attribute?(m)
  self[m]
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



39
40
41
# File 'app/models/dunlop/attribute_changes_tracking.rb', line 39

def target
  @target
end

Instance Method Details

#[](val) ⇒ Object



49
50
51
# File 'app/models/dunlop/attribute_changes_tracking.rb', line 49

def [](val)
  target.last_attribute_changes.find{|changed| changed.attribute_name == val.to_s }.try(:changed_at)
end