Module: Eco::Data::Locations::NodeDiff::Accessors::ClassMethods

Includes:
Strings::SnakeCase
Defined in:
lib/eco/data/locations/node_diff/accessors.rb

Instance Method Summary collapse

Methods included from Strings::SnakeCase

#snake_case

Instance Method Details

#attr_expose(*attrs) ⇒ Object

Note:

the defined attributes are expected to be the keys within the source Hashes that are being compared.

Note:

accessing src_1 (prev) attributes, will have it's method as prev_[attrName]

Creates the defined accessor attributes against NodeDiff It also creates a method with question mark that evaluates true if any the attr changed.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/eco/data/locations/node_diff/accessors.rb', line 21

def attr_expose(*attrs)
  attrs.each do |attr|
    meth  = attr.to_sym
    methp = :"#{meth}_prev"
    methq = :"#{meth}?"

    # current value

    define_method meth do
      attr(meth)
    end
    alias_method snake_case(meth), meth

    # prev value

    define_method methp do
      attr_prev(meth)
    end
    alias_method snake_case(methp), methp

    # has it changed?

    define_method methq do
      diff_attr?(meth)
    end
    alias_method snake_case(methq), methq

    @exposed_attrs = (@exposed_attrs || []) | [meth]
  end
end

#exposed_attrsObject

Keeps track on what attributes have been exposed.



50
51
52
# File 'lib/eco/data/locations/node_diff/accessors.rb', line 50

def exposed_attrs
  @exposed_attrs ||= []
end