Module: LtdTemplate::Value

Includes:
Method_Handler
Included in:
Proxy, Code_Block, Namespace
Defined in:
lib/ltdtemplate/value.rb,
lib/ltdtemplate/value/array_splat.rb

Defined Under Namespace

Classes: Array_Splat, Code_Block, Namespace

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#runtime_methodsArray<LtdTemplate::Value::Code_Block> (readonly)

This object’s run-time methods.

Returns:



21
22
23
# File 'lib/ltdtemplate/value.rb', line 21

def runtime_methods
  @runtime_methods
end

Class Method Details

.included(base) ⇒ Object



16
# File 'lib/ltdtemplate/value.rb', line 16

def self.included (base); base.extend LtdTemplate::Consumer; end

Instance Method Details

#do_methods(opts) ⇒ nil

Set or get run-time methods.

Parameters:

  • opts (Hash)

    A hash of method options.

Returns:

  • (nil)


56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ltdtemplate/value.rb', line 56

def do_methods (opts)
	if params = opts[:parameters]
 params.values(:seq).each_slice(2) do |pair|
		return @runtime_methods[pair[0]] if pair.size == 1
		if pair[1].nil? then @runtime_methods.delete pair[0]
		else @runtime_methods[pair[0]] = pair[1]
		end
 end
	end
	nil
end

#do_run_method(opts) ⇒ Object

Try to execute run-time methods bound to the object or object class. Returns the return value from the code block or nil.

Parameters:

  • opts (Hash)

    A hash of method options.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ltdtemplate/value.rb', line 72

def do_run_method (opts)
	method = nil
	if name = opts[:method]
 method = @runtime_methods[name]
 class_name = self.evaluate :method => 'class'
 if !method && class_name
		class_var = @template.factory(:variable, class_name).evaluate
		method = rubyversed(class_var).runtime_methods[name] if class_var
 end
	end
	if method.is_a? LtdTemplate::Value::Code_Block
 opts[:target] = self
 rubyversed(method).evaluate opts
	elsif !method.nil? then method
	elsif mmproc = @template.options[:missing_method]
 mmproc.call(@template, self, opts)
	else nil
	end
end

#evaluate(opts = {}) ⇒ Object

Common operations for all values



32
33
34
35
36
37
# File 'lib/ltdtemplate/value.rb', line 32

def evaluate (opts = {})
	case opts[:method]
	when 'methods' then do_methods opts
	else do_run_method opts
	end
end

#initialize(template) ⇒ Object

Initialize the object with a link to the associated template.

Parameters:

  • template (LtdTemplate)

    The associated template object.



26
27
28
29
# File 'lib/ltdtemplate/value.rb', line 26

def initialize (template)
	@template = template
	@runtime_methods = {}
end

#inspectObject

Avoid “spilling our guts” when inspected



40
41
42
# File 'lib/ltdtemplate/value.rb', line 40

def inspect
	"#<#{self.class.name}##{self.object_id} for #{@template.inspect}>"
end

#rubyversed(obj) ⇒ Object

Shortcut to rubyversed in the template.



45
# File 'lib/ltdtemplate/value.rb', line 45

def rubyversed (obj); @template.rubyversed(obj); end

#tpl_booleanObject

Default boolean value is true



48
# File 'lib/ltdtemplate/value.rb', line 48

def tpl_boolean; true; end