module LtdTemplate::Value

Attributes

runtime_methods[R]

@!attribute [r] runtime_methods @return [Array<LtdTemplate::Value::Code_Block>] This object's run-time methods.

Public Class Methods

included(base) click to toggle source
# File lib/ltdtemplate/value.rb, line 16
def self.included (base); base.extend LtdTemplate::Consumer; end
new(template) click to toggle source

Initialize the object with a link to the associated template.

@param template [LtdTemplate] The associated template object.

# File lib/ltdtemplate/value.rb, line 26
def initialize (template)
    @template = template
    @runtime_methods = {}
end

Public Instance Methods

do_methods(opts) click to toggle source

Set or get run-time methods.

@param opts [Hash] A hash of method options. @return [nil]

# 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) click to toggle source

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

@param opts [Hash] A hash of method options.

# 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 = {}) click to toggle source

Common operations for all values

# 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
inspect() click to toggle source

Avoid “spilling our guts” when inspected

# File lib/ltdtemplate/value.rb, line 40
def inspect
    "#<#{self.class.name}##{self.object_id} for #{@template.inspect}>"
end
rubyversed(obj) click to toggle source

Shortcut to rubyversed in the template.

# File lib/ltdtemplate/value.rb, line 45
def rubyversed (obj); @template.rubyversed(obj); end
tpl_boolean() click to toggle source

Default boolean value is true

# File lib/ltdtemplate/value.rb, line 48
def tpl_boolean; true; end