class Declarative::Definitions
Public Class Methods
new(definition_class)
click to toggle source
Calls superclass method
# File lib/declarative/definitions.rb, line 24 def initialize(definition_class) @definition_class = definition_class super() end
Public Instance Methods
add(name, options={}, &block)
click to toggle source
add
is high-level behavior for Definitions#[]=. reserved options:
:_features :_defaults :_base :_nested_builder
# File lib/declarative/definitions.rb, line 39 def add(name, options={}, &block) options = options[:_defaults].(name, options) if options[:_defaults] # FIXME: pipeline? base = options[:_base] if options.delete(:inherit) and (parent_property = get(name)) base = parent_property[:nested] options = parent_property.merge(options) # TODO: Definition#merge end if options[:_nested_builder] options[:nested] = build_nested( options.merge( _base: base, _name: name, _block: block, ) ) end # clean up, we don't want that stored in the Definition instance. [:_defaults, :_base, :_nested_builder, :_features].each { |key| options.delete(key) } self[name.to_s] = @definition_class.new(name, options) end
each(&block)
click to toggle source
# File lib/declarative/definitions.rb, line 29 def each(&block) # TODO : test me! values.each(&block) end
get(name)
click to toggle source
# File lib/declarative/definitions.rb, line 64 def get(name) self[name.to_s] end
Private Instance Methods
build_nested(options)
click to toggle source
Run builder to create nested schema (or twin, or representer, or whatever).
# File lib/declarative/definitions.rb, line 70 def build_nested(options) options[:_nested_builder].(options) end