class Sequoia::Builder
Class: Config builder
Yields the block with definitions and then build keys and values Also works as a chainable builder
Attributes
Storage for builded attributes
Public Class Methods
Private: Initialize a new Builder
Params:
-
attrs {Sequoia::Store} For internal use only (optional)
Yields: block with key-value definitions
# File lib/sequoia/builder.rb, line 50 def initialize(attrs=Store.new, &block) @attrs = attrs instance_eval(&block) if ::Kernel.block_given? end
Public Instance Methods
Returns the class of object
This method must always be called with an explicit receiver, as ‘class` is also a reserved word in Ruby
# File lib/sequoia/builder.rb, line 20 def class Builder end
Of course we respond to any key name
# File lib/sequoia/builder.rb, line 27 def respond_to?(*) true end
Represent builder as string
# File lib/sequoia/builder.rb, line 34 def to_s "#<Sequoia::Builder attrs=#{attrs}>" end
Private Instance Methods
Private: Method missing handler
This is where all the magic happens
Params:
-
method_name {Symbol} Method name
-
args {Array} Array of arguments sended to the method
Yields: Block with nested definitions
# File lib/sequoia/builder.rb, line 66 def method_missing(method_name, *args, &block) key = normalize_method_name(method_name) if args.length > 0 attrs[key] = args.length > 1 ? args : args[0] else attrs[key] ||= Store.new self.class.new(attrs[key], &block) end end
Private: Remove trailing ‘=` from getter name if exists
Params:
-
method_name {Symbol} Method name
Returns: {Symbol} Normalized method name
# File lib/sequoia/builder.rb, line 85 def normalize_method_name(method_name) method_string = method_name.to_s method_string.chop! if method_string.end_with?('=') method_string.to_sym end