class ViewModel::Changes
Attributes
changed_associations[R]
changed_attributes[R]
changed_nested_children[R]
changed_nested_children?[R]
changed_referenced_children[R]
changed_referenced_children?[R]
deleted[R]
deleted?[R]
new[R]
new?[R]
Public Class Methods
new(new: false, changed_attributes: [], changed_associations: [], changed_nested_children: false, changed_referenced_children: false, deleted: false)
click to toggle source
# File lib/view_model/changes.rb, line 15 def initialize(new: false, changed_attributes: [], changed_associations: [], changed_nested_children: false, changed_referenced_children: false, deleted: false) @new = new @changed_attributes = changed_attributes.map(&:to_s) @changed_associations = changed_associations.map(&:to_s) @changed_nested_children = changed_nested_children @changed_referenced_children = changed_referenced_children @deleted = deleted end
Public Instance Methods
==(other)
click to toggle source
# File lib/view_model/changes.rb, line 58 def ==(other) return false unless other.is_a?(ViewModel::Changes) self.new? == other.new? && self.changed_nested_children? == other.changed_nested_children? && self.changed_referenced_children? == other.changed_referenced_children? && self.deleted? == other.deleted? && self.changed_attributes.contains_exactly?(other.changed_attributes) && self.changed_associations.contains_exactly?(other.changed_associations) end
Also aliased as: eql?
changed?()
click to toggle source
# File lib/view_model/changes.rb, line 35 def changed? new? || deleted? || changed_attributes.present? || changed_associations.present? end
changed_any?(associations: [], attributes: [])
click to toggle source
# File lib/view_model/changes.rb, line 30 def changed_any?(associations: [], attributes: []) associations.any? { |assoc| changed_associations.include?(assoc.to_s) } || attributes.any? { |attr| changed_attributes.include?(attr.to_s) } end
changed_nested_tree?()
click to toggle source
# File lib/view_model/changes.rb, line 39 def changed_nested_tree? changed? || changed_nested_children? end
changed_owned_tree?()
click to toggle source
# File lib/view_model/changes.rb, line 43 def changed_owned_tree? changed? || changed_nested_children? || changed_referenced_children? end
contained_to?(associations: [], attributes: [])
click to toggle source
# File lib/view_model/changes.rb, line 24 def contained_to?(associations: [], attributes: []) !deleted? && changed_associations.all? { |assoc| associations.include?(assoc.to_s) } && changed_attributes.all? { |attr| attributes.include?(attr.to_s) } end
to_h()
click to toggle source
# File lib/view_model/changes.rb, line 47 def to_h { 'changed_attributes' => changed_attributes.dup, 'changed_associations' => changed_associations.dup, 'new' => new?, 'changed_nested_children' => changed_nested_children?, 'changed_referenced_children' => changed_referenced_children?, 'deleted' => deleted?, } end