Class: LtdTemplate::Code::Call

Inherits:
LtdTemplate::Code show all
Defined in:
lib/ltdtemplate/code/call.rb

Instance Attribute Summary

Attributes inherited from LtdTemplate::Code

#tpl_methods

Instance Method Summary collapse

Methods inherited from LtdTemplate::Code

#do_method, #do_set, instance, #is_set?, #set_value

Constructor Details

#initialize(template, target, method, parameters) ⇒ Call

Initialize a method call object.

Parameters:



17
18
19
20
# File 'lib/ltdtemplate/code/call.rb', line 17

def initialize (template, target, method, parameters)
	super template
	@target, @method, @parameters = target, method, parameters
end

Instance Method Details

#get_item(key) ⇒ Object



43
# File 'lib/ltdtemplate/code/call.rb', line 43

def get_item (key); get_value.get_item key; end

#get_value(opts = {}) ⇒ Object

Return the result of executing the call.

Parameters:

  • opts (Hash) (defaults to: {})

    Option hash

Options Hash (opts):

  • :method (String)

    A method to call on the return value



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ltdtemplate/code/call.rb', line 26

def get_value (opts = {})
	# Increase the call count and call depth.
	@template.use :calls
	@template.use :call_depth

	result = @target.get_value({ :method => @method,
	  :parameters => @parameters.get_value })

	# Decrease the call depth.
	@template.use :call_depth, -1

	opts[:method] ? result.get_value(opts) : result
end

#has_item?(key) ⇒ Boolean

Pass has/get/set_item calls through to result of call; in some cases it might be the same value each time.

Returns:

  • (Boolean)


42
# File 'lib/ltdtemplate/code/call.rb', line 42

def has_item? (key); get_value.has_item? key; end

#set_item(key, value) ⇒ Object



44
# File 'lib/ltdtemplate/code/call.rb', line 44

def set_item (key, value); get_value.set_item key, value; end