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.
7 8 9 10 11 |
# File 'lib/graphql/analysis/reducer_state.rb', line 7 def initialize(reducer, query) @reducer = reducer @memo = initialize_reducer(reducer, query) @errors = [] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/graphql/analysis/reducer_state.rb', line 5 def errors @errors end |
#memo ⇒ Object
Returns the value of attribute memo.
5 6 7 |
# File 'lib/graphql/analysis/reducer_state.rb', line 5 def memo @memo end |
#reducer ⇒ Object (readonly)
Returns the value of attribute reducer.
4 5 6 |
# File 'lib/graphql/analysis/reducer_state.rb', line 4 def reducer @reducer end |
Instance Method Details
#call(visit_type, irep_node) ⇒ Object
13 14 15 16 17 |
# File 'lib/graphql/analysis/reducer_state.rb', line 13 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.
23 24 25 26 27 28 29 30 31 |
# File 'lib/graphql/analysis/reducer_state.rb', line 23 def finalize_reducer if @errors.any? @errors elsif reducer.respond_to?(:final_value) reducer.final_value(@memo) else @memo end end |