Module: Dinamo::Model::Dirty

Extended by:
ActiveSupport::Concern
Included in:
Dinamo::Model
Defined in:
lib/dinamo/model/dirty.rb

Instance Method Summary collapse

Instance Method Details

#attribute_changed?(attr) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dinamo/model/dirty.rb', line 34

def attribute_changed?(attr)
  changed.include?(attr.to_s)
end

#changedObject



17
18
19
# File 'lib/dinamo/model/dirty.rb', line 17

def changed
  changed_attributes.keys
end

#changed?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dinamo/model/dirty.rb', line 21

def changed?
  !changed_attributes.empty?
end

#changed_attributesObject



30
31
32
# File 'lib/dinamo/model/dirty.rb', line 30

def changed_attributes
  @changed_attributes ||= ActiveSupport::HashWithIndifferentAccess.new
end

#changesObject



25
26
27
28
# File 'lib/dinamo/model/dirty.rb', line 25

def changes
  map = changed.map { |attr| [attr, attribute_change(attr)] }
  ActiveSupport::HashWithIndifferentAccess[map]
end

#changes_appliedObject



38
39
40
41
# File 'lib/dinamo/model/dirty.rb', line 38

def changes_applied
  @previously_changed = changes
  @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end

#clear_changes_informationObject



43
44
45
46
# File 'lib/dinamo/model/dirty.rb', line 43

def clear_changes_information
  @previously_changed = ActiveSupport::HashWithIndifferentAccess.new
  @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end

#clear_previous_attributesObject



48
49
50
# File 'lib/dinamo/model/dirty.rb', line 48

def clear_previous_attributes
  @previously_changed = ActiveSupport::HashWithIndifferentAccess.new
end