Module: Babl::Operators::Call::DSL

Included in:
Template
Defined in:
lib/babl/operators/call.rb

Instance Method Summary collapse

Instance Method Details

#call(*args, &block) ⇒ Object

Interpret whatever is passed to this method as BABL template. It is idempotent.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/babl/operators/call.rb', line 10

def call(*args, &block)
    return with(*args, &block) unless block.nil?
    raise Errors::InvalidTemplate, 'call() expects exactly 1 argument (unless block)' unless args.size == 1

    arg = args.first

    case arg
    when Template then self.class.new(builder.wrap { |bound| arg.builder.bind(bound) })
    when Utils::DslProxy then call(arg.itself)
    when ::Symbol then nav(arg)
    when ::Proc then call(&arg)
    when ::Hash then object(arg)
    when ::Array then array(*arg)
    when ::String, ::Numeric, ::NilClass, ::TrueClass, ::FalseClass then static(arg)
    else raise Errors::InvalidTemplate, "call() received invalid argument: #{arg}"
    end
end