Class: GraphQL::Analysis::ReducerState
- Inherits:
-
Object
- Object
- GraphQL::Analysis::ReducerState
- Defined in:
- lib/graphql/analysis/reducer_state.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#memo ⇒ Object
Returns the value of attribute memo.
-
#reducer ⇒ Object
readonly
Returns the value of attribute reducer.
Instance Method Summary collapse
-
#call(visit_type, irep_node) ⇒ Object
-
#finalize_reducer ⇒ Any
Respond with any errors, if found.
-
#initialize(reducer, query) ⇒ ReducerState
constructor
A new instance of ReducerState.
Constructor Details
#initialize(reducer, query) ⇒ ReducerState
Returns a new instance of ReducerState
8 9 10 11 12 |
# File 'lib/graphql/analysis/reducer_state.rb', line 8 def initialize(reducer, query) @reducer = reducer @memo = initialize_reducer(reducer, query) @errors = [] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors
6 7 8 |
# File 'lib/graphql/analysis/reducer_state.rb', line 6 def errors @errors end |
#memo ⇒ Object
Returns the value of attribute memo
6 7 8 |
# File 'lib/graphql/analysis/reducer_state.rb', line 6 def memo @memo end |
#reducer ⇒ Object (readonly)
Returns the value of attribute reducer
5 6 7 |
# File 'lib/graphql/analysis/reducer_state.rb', line 5 def reducer @reducer end |
Instance Method Details
#call(visit_type, irep_node) ⇒ Object
14 15 16 17 18 |
# File 'lib/graphql/analysis/reducer_state.rb', line 14 def call(visit_type, irep_node) @memo = @reducer.call(@memo, visit_type, irep_node) rescue AnalysisError => err @errors << err end |
#finalize_reducer ⇒ Any
Respond with any errors, if found. Otherwise, if the reducer accepts
final_value
, send it the last memo value.
Otherwise, use the last value from the traversal.
24 25 26 27 28 29 30 31 32 |
# File 'lib/graphql/analysis/reducer_state.rb', line 24 def finalize_reducer if @errors.any? @errors elsif reducer.respond_to?(:final_value) reducer.final_value(@memo) else @memo end end |