Class: CabezaDeTermo::JsonSpec::JsonObject
- Inherits:
-
JsonExpression
- Object
- JsonExpression
- CabezaDeTermo::JsonSpec::JsonObject
- Defined in:
- lib/cabeza-de-termo/json-spec/expressions/json-object.rb
Overview
A JsonExpression representing an object in a json parse tree.
Instance Method Summary collapse
-
#accept_walker(expression_walker) ⇒ Object
Walking expressions.
- #add_field_expression(field_expression) ⇒ Object
- #default_expectations ⇒ Object
- #each_field(&block) ⇒ Object
-
#each_field_expression ⇒ Object
Answer the each_field expression of self object.
-
#expect(field_name) ⇒ Object
Creating fields.
-
#fields ⇒ Object
Answer the fields of self json object.
-
#has_each_field? ⇒ Boolean
Answer whether self object has a each_field expression defined or no.
-
#initialize(parent_expression) ⇒ JsonObject
constructor
A new instance of JsonObject.
Methods inherited from JsonExpression
#add_default_expectations, #add_expectation, #add_expectation_from_library, #default_expectations_for, #expectations_library, #expectations_runner, #is_a_modifier_library_method?, #is_an_expectations_library_method?, #json_spec, #method_missing, #new_any_of_expression, #new_anything_expression, #new_each_field, #new_expectations_runner, #new_expression_for, #new_json_each_expression, #new_json_field_name_expression, #new_list_expression, #new_named_field_expression, #new_object_expression, #new_scalar_expression, #parent_expression, #perform_modifier_from_library, #run_modifier, #set_expectations_runner, #set_parent_expression, #to_be_as_defined_by, #to_be_as_defined_in
Constructor Details
#initialize(parent_expression) ⇒ JsonObject
Returns a new instance of JsonObject.
9 10 11 12 13 14 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 9 def initialize(parent_expression) super(parent_expression) @fields = [] @each_field_expression = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CabezaDeTermo::JsonSpec::JsonExpression
Instance Method Details
#accept_walker(expression_walker) ⇒ Object
Walking expressions
77 78 79 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 77 def accept_walker(expression_walker) expression_walker.walk_json_object(self) end |
#add_field_expression(field_expression) ⇒ Object
69 70 71 72 73 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 69 def add_field_expression(field_expression) fields << field_expression self end |
#default_expectations ⇒ Object
16 17 18 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 16 def default_expectations default_expectations_for(:objects) end |
#each_field(&block) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 61 def each_field(&block) @each_field_expression = new_each_field CdT.bind_block_evaluation_to @each_field_expression, &block unless block.nil? @each_field_expression end |
#each_field_expression ⇒ Object
Answer the each_field expression of self object.
36 37 38 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 36 def each_field_expression() @each_field_expression end |
#expect(field_name) ⇒ Object
Creating fields
53 54 55 56 57 58 59 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 53 def expect(field_name) field_expression = new_named_field_expression(field_name) add_field_expression(field_expression) field_expression end |
#fields ⇒ Object
Answer the fields of self json object.
27 28 29 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 27 def fields() @fields end |
#has_each_field? ⇒ Boolean
Answer whether self object has a each_field expression defined or no.
47 48 49 |
# File 'lib/cabeza-de-termo/json-spec/expressions/json-object.rb', line 47 def has_each_field?() !each_field_expression.nil? end |