Module: CabezaDeTermo::JsonSpec::ValueHoldersStackBehaviour

Included in:
JsonExpectationsRunner
Defined in:
lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb

Instance Method Summary collapse

Instance Method Details

#initializeObject

Accessing



8
9
10
11
# File 'lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb', line 8

def initialize()
	@value_holder = nil
	@value_holders_stack = []
end

#new_value_holder_on(value) ⇒ Object

Instance creation



52
53
54
# File 'lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb', line 52

def new_value_holder_on(value)
	ValueHolder.new(value)
end

#pop_value_holderObject



32
33
34
35
36
37
38
39
# File 'lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb', line 32

def pop_value_holder()
	@value_holders_stack.pop
	if @value_holders_stack.empty?
		@value_holder = nil
	else
		@value_holder = @value_holders_stack.last
	end
end

#push_value_holder(value_holder) ⇒ Object

ValueHolders stack



27
28
29
30
# File 'lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb', line 27

def push_value_holder(value_holder)
	@value_holder = value_holder
	@value_holders_stack << @value_holder
end

#walk_with_json(json_expression, json) ⇒ Object

Walking



15
16
17
# File 'lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb', line 15

def walk_with_json(json_expression, json)
	walk_with_value_holder(json_expression, new_value_holder_on(json))
end

#walk_with_value_holder(json_expression, value_holder) ⇒ Object



19
20
21
22
23
# File 'lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb', line 19

def walk_with_value_holder(json_expression, value_holder)
	with_value_holder(value_holder) do
		walk_on(json_expression)
	end
end

#with_value_holder(value_holder, &block) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb', line 41

def with_value_holder(value_holder, &block)
	push_value_holder(value_holder)
	begin
		block.call
	ensure
		pop_value_holder
	end
end