Module: Eco::Data::Locations::NodeDiff::NodesDiff::Selectors

Included in:
Eco::Data::Locations::NodeDiff::NodesDiff
Defined in:
lib/eco/data/locations/node_diff/nodes_diff/selectors.rb

Instance Method Summary collapse

Instance Method Details

#selector(*attrs) ⇒ Object

Note:

the selector method name with a question mark should exist in the diff_result_class

Creates selector methods on diffs (nodes that changed) It also creates a method with question mark that evaluates true if any diff matches.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/eco/data/locations/node_diff/nodes_diff/selectors.rb', line 6

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

    define_method meth do
      diffs.select(&methq)
    end

    define_method methq do
      diffs.any?(&methq)
    end
  end
end