Class: ROM::Commands::Graph::InputEvaluator Private
- Inherits:
-
Object
- Object
- ROM::Commands::Graph::InputEvaluator
- Defined in:
- lib/rom/commands/graph/input_evaluator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Evaluator for lazy commands which extracts values for commands from nested hashes
Instance Attribute Summary collapse
- #exclude_proc ⇒ Object readonly private
- #excluded_keys ⇒ Object readonly private
- #tuple_path ⇒ Object readonly private
Class Method Summary collapse
-
.build(tuple_path, nodes) ⇒ InputEvaluator
private
Build an input evaluator.
-
.exclude_proc(excluded_keys) ⇒ Object
private
Return default exclude_proc.
- .extract_excluded_keys(nodes) ⇒ Object private
Instance Method Summary collapse
-
#call(input, index = nil) ⇒ Hash
private
Evaluate input hash.
-
#initialize(tuple_path, excluded_keys) ⇒ InputEvaluator
constructor
private
Initialize a new input evaluator.
Constructor Details
#initialize(tuple_path, excluded_keys) ⇒ InputEvaluator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new input evaluator
57 58 59 60 61 |
# File 'lib/rom/commands/graph/input_evaluator.rb', line 57 def initialize(tuple_path, excluded_keys) @tuple_path = tuple_path @excluded_keys = excluded_keys @exclude_proc = self.class.exclude_proc(excluded_keys) end |
Instance Attribute Details
#exclude_proc ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/rom/commands/graph/input_evaluator.rb', line 20 def exclude_proc @exclude_proc end |
#excluded_keys ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/rom/commands/graph/input_evaluator.rb', line 16 def excluded_keys @excluded_keys end |
#tuple_path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rom/commands/graph/input_evaluator.rb', line 12 def tuple_path @tuple_path end |
Class Method Details
.build(tuple_path, nodes) ⇒ InputEvaluator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build an input evaluator
30 31 32 |
# File 'lib/rom/commands/graph/input_evaluator.rb', line 30 def self.build(tuple_path, nodes) new(tuple_path, extract_excluded_keys(nodes)) end |
.exclude_proc(excluded_keys) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return default exclude_proc
48 49 50 |
# File 'lib/rom/commands/graph/input_evaluator.rb', line 48 def self.exclude_proc(excluded_keys) -> input { input.reject { |k, _| excluded_keys.include?(k) } } end |
.extract_excluded_keys(nodes) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 40 41 42 43 |
# File 'lib/rom/commands/graph/input_evaluator.rb', line 35 def self.extract_excluded_keys(nodes) return unless nodes nodes .map { |item| item.is_a?(Array) && item.size > 1 ? item.first : item } .compact .map { |item| item.is_a?(Hash) ? item.keys.first : item } .reject { |item| item.is_a?(Array) } end |
Instance Method Details
#call(input, index = nil) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluate input hash
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rom/commands/graph/input_evaluator.rb', line 69 def call(input, index = nil) value = begin if index tuple_path[0..tuple_path.size-2] .reduce(input) { |a, e| a.fetch(e) } .at(index)[tuple_path.last] else tuple_path.reduce(input) { |a, e| a.fetch(e) } end rescue KeyError => e raise KeyMissing, e. end if excluded_keys value.is_a?(Array) ? value.map(&exclude_proc) : exclude_proc[value] else value end end |