Class: CabezaDeTermo::JsonSpec::JsonField

Inherits:
JsonExpression show all
Defined in:
lib/cabeza-de-termo/json-spec/expressions/json-field.rb

Overview

A JsonExpression representing an objects field in a json parse tree.

Instance Method Summary collapse

Methods inherited from JsonExpression

#add_default_expectations, #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, #set_expectations_runner, #set_parent_expression, #to_be_as_defined_by, #to_be_as_defined_in

Constructor Details

#initialize(parent_expression, name) ⇒ JsonField

Returns a new instance of JsonField.

Parameters:

  • JsonExpression

    parent_expression The parent expression of self field

  • string

    name The name of the field



14
15
16
17
18
19
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 14

def initialize(parent_expression, name)
	@name = name
	@value_expression = new_anything_expression

	super(parent_expression)
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



71
72
73
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 71

def accept_walker(expression_walker)
	expression_walker.walk_json_field(self)
end

#add_expectation(expectation) ⇒ Object



41
42
43
44
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 41

def add_expectation(expectation)
	value_expression.add_expectation(expectation)
	self
end

#default_expectationsObject



21
22
23
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 21

def default_expectations
	default_expectations_for(:fields)
end

#nameObject

Accessing



52
53
54
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 52

def name()
	@name
end

#run_modifier(modifier) ⇒ Object



46
47
48
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 46

def run_modifier(modifier)
	value_expression.run_modifier(modifier)
end

#set_value_expression(expression) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 60

def set_value_expression(expression)
	expression.set_parent_expression(self)
	@value_expression = expression

	add_default_expectations

	expression
end

#to_be(type, &block) ⇒ Object

Expectations



27
28
29
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 27

def to_be(type, &block)
	to_be_a(type, &block)
end

#to_be_a(type, &block) ⇒ Object



35
36
37
38
39
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 35

def to_be_a(type, &block)
	expression = set_value_expression( new_expression_for(type) )
	CdT.bind_block_evaluation_to expression, &block unless block.nil?
	expression
end

#to_be_an(type, &block) ⇒ Object



31
32
33
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 31

def to_be_an(type, &block)
	to_be_a(type, &block)
end

#value_expressionObject



56
57
58
# File 'lib/cabeza-de-termo/json-spec/expressions/json-field.rb', line 56

def value_expression()
	@value_expression
end