Class: ROM::Commands::Graph::InputEvaluator Private
- Inherits:
-
Object
- Object
- ROM::Commands::Graph::InputEvaluator
- Defined in:
- core/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
59 60 61 62 63 |
# File 'core/lib/rom/commands/graph/input_evaluator.rb', line 59 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.
22 23 24 |
# File 'core/lib/rom/commands/graph/input_evaluator.rb', line 22 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.
18 19 20 |
# File 'core/lib/rom/commands/graph/input_evaluator.rb', line 18 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.
14 15 16 |
# File 'core/lib/rom/commands/graph/input_evaluator.rb', line 14 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
32 33 34 |
# File 'core/lib/rom/commands/graph/input_evaluator.rb', line 32 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
50 51 52 |
# File 'core/lib/rom/commands/graph/input_evaluator.rb', line 50 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.
37 38 39 40 41 42 43 44 45 |
# File 'core/lib/rom/commands/graph/input_evaluator.rb', line 37 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
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'core/lib/rom/commands/graph/input_evaluator.rb', line 71 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 |