module Eco::Data::Locations # Differences between node before and after # @note this works with `Hash` object where basic keys are: # - `nodeId` # - `name` # - `parentId` # - `archived` # @note other properties can be part of the `Hash` although # they may not influence the results. class NodeDiff < Eco::Data::Hashes::DiffResult require_relative 'node_diff/accessors' require_relative 'node_diff/selectors' require_relative 'node_diff/nodes_diff' include Eco::Data::Locations::NodeDiff::Accessors key :nodeId compare :parentId, :name, :archived case_sensitive false attr_expose :nodeId, :name, :parentId, :archived alias_method :insert?, :new? alias_method :diff_name_src?, :diff_name? # Has the property `name` changed? def diff_name? diff_name_src? && update? end alias_method :name?, :diff_name? alias_method :id? , :diff_name? # currently a change of name is a change of id (tag) #alias_method :id? , :key? #alias_method :nodeId? , :id? # Has any of `id` or `name` properties changed? def id_name? id? || diff_name? end # Has the parent id changed? def move? update? && diff_parentId? end # Has the `archived` property changed and it was `true`? def unarchive? !archived && update? && diff_archived? end # Has the `archived` property changed and it was `false`? def archive? !prev_archived && (del? || archived) end end end