class Serial::Builder
@api private
Builder
contains common methods to the serializer DSL.
Attributes
data[R]
Builder
data, depends on what kind of builder it is.
@return [Array, Hash]
Public Class Methods
build(context, *args, &block)
click to toggle source
Create the builder, execute the block inside it, and return its' data. Any superflous arguments are given to {#exec}.
@param context [#instance_exec, nil] the context to execute block inside @yield (see exec
) @yieldparam (see exec
) @return [#data]
# File lib/serial/builder.rb, line 13 def self.build(context, *args, &block) builder = new(context) builder.exec(*args, &block) builder.data end
Public Instance Methods
exec(*args, &block)
click to toggle source
Executes a block in the configured context, if there is one, otherwise using regular closure scoping.
@yield [self, *args] @yieldparam self [Builder] passes in self as the first parameter. @yieldparam *args superflous arguments are passed to the block.
# File lib/serial/builder.rb, line 30 def exec(*args, &block) if @context @context.instance_exec(self, *args, &block) elsif block block.call(self, *args) else raise ArgumentError, "no serializer block given" end end