Class: GraphQL::Execution::Interpreter::HashResponse
- Inherits:
-
Object
- Object
- GraphQL::Execution::Interpreter::HashResponse
- Defined in:
- lib/graphql/execution/interpreter/hash_response.rb
Overview
This response class handles #write
by accumulating
values into a Hash.
Instance Method Summary collapse
-
#final_value ⇒ Object
-
#initialize ⇒ HashResponse
constructor
A new instance of HashResponse.
-
#inspect ⇒ Object
-
#write(path, value) ⇒ void
Add
value
atpath
.
Constructor Details
#initialize ⇒ HashResponse
Returns a new instance of HashResponse
9 10 11 |
# File 'lib/graphql/execution/interpreter/hash_response.rb', line 9 def initialize @result = {} end |
Instance Method Details
#final_value ⇒ Object
13 14 15 |
# File 'lib/graphql/execution/interpreter/hash_response.rb', line 13 def final_value @result end |
#inspect ⇒ Object
17 18 19 |
# File 'lib/graphql/execution/interpreter/hash_response.rb', line 17 def inspect "#<#{self.class.name} result=#{@result.inspect}>" end |
#write(path, value) ⇒ void
This method returns an undefined value.
Add value
at path
.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/graphql/execution/interpreter/hash_response.rb', line 23 def write(path, value) if path.empty? @result = value elsif (write_target = @result) i = 0 prefinal_steps = path.size - 1 # Use `while` to avoid a closure while i < prefinal_steps path_part = path[i] i += 1 write_target = write_target[path_part] end path_part = path[i] write_target[path_part] = value else # The response is completely nulled out end nil end |