Module: Babl::Operators::Call::DSL
- Included in:
- Template
- Defined in:
- lib/babl/operators/call.rb
Instance Method Summary collapse
-
#call(*args, &block) ⇒ Object
Interpret whatever is passed to this method as BABL template.
Instance Method Details
#call(*args, &block) ⇒ Object
Interpret whatever is passed to this method as BABL template. It is idempotent.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/babl/operators/call.rb', line 8 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 self.class then self.class.new(builder.wrap { |bound| arg.builder.bind(bound) }) when ::Symbol then nav(arg) when ::Proc then call(&arg) when ::Hash then object(**arg.map { |k, v| [:"#{k}", v] }.to_h) 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 |