Module: MadderLib::Conditional::Registry::Instance

Included in:
Instruction, Phrase
Defined in:
lib/madderlib/conditional/registry.rb

Instance Method Summary collapse

Instance Method Details

#prepare(context) ⇒ Object

called once per execution



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/madderlib/conditional/registry.rb', line 30

def prepare(context)
	#	execute all of our registered preparation blocks
	self.class.conditional_prepares.each do |block|
		(block.arity == 1 ? block.call(self) : block.call(self, context))
	end

	if self.methods.include?('instructions')
		#	prepare each instruction
		self.instructions.each {|instruction| instruction.prepare(context) }
	end
end

#test(context) ⇒ Object

returns true if the owner should be used



43
44
45
46
47
48
49
50
51
52
# File 'lib/madderlib/conditional/registry.rb', line 43

def test(context)
	#	find the first failing test closure
	#		it'd be nil if they all pass
	failed = self.class.conditional_tests.find do |block|
		#	first failure stops us
		(! (block.arity == 1 ? block.call(self) : block.call(self, context)))
	end

	failed.nil?
end