Class: Bade::Runtime::Mixin
Instance Attribute Summary
Attributes inherited from Block
#block, #name, #render_binding
Instance Method Summary collapse
Methods inherited from Block
#call, #initialize, #render, #render!
Constructor Details
This class inherits a constructor from Bade::Runtime::Block
Instance Method Details
#call!(blocks, *args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bade/runtime/mixin.rb', line 8 def call!(blocks, *args) block.call(blocks, *args) rescue ArgumentError => e case e. when /\Awrong number of arguments \(given ([0-9]+), expected ([0-9]+)\)\Z/, /\Awrong number of arguments \(([0-9]+) for ([0-9]+)\)\Z/ # handle incorrect parameters count # minus one, because first argument is always hash of blocks given = $1.to_i - 1 expected = $2.to_i - 1 raise ArgumentError, "wrong number of arguments (given #{given}, expected #{expected}) for mixin `#{name}`" when /\Aunknown keyword: (.*)\Z/ # handle unknown key-value parameter key_name = $1 raise ArgumentError, "unknown key-value argument `#{key_name}` for mixin `#{name}`" else raise end rescue Block::MissingBlockDefinitionError => e msg = case e.context when :call "Mixin `#{name}` requires block to get called of block `#{e.name}`" when :render "Mixin `#{name}` requires block to get rendered content of block `#{e.name}`" else raise ::ArgumentError, "Unknown context #{e.context} of error #{e}!" end raise Block::MissingBlockDefinitionError.new(e.name, e.context, msg) end |