module Krikri::MappingDSL

Mixin implementing DSL methods for metadata mapping. The main MappingDSL module implements the core property definition methods, while nested modules add various extensions.

Public Instance Methods

method_missing(name, *args, &block) click to toggle source

The class responds to all methods; treating any not defined as property/child declarations.

@return [PropertyDeclaration, ChildDeclaration]

# File lib/krikri/mapping_dsl.rb, line 36
def method_missing(name, *args, &block)
  return add_child(name, *args, &block) if block && block.arity == 0
  add_property(name, *args, &block)
end
properties() click to toggle source

List the property and child declarations set on mapping.

@return [Array<PropertyDeclaration, ChildDeclaration>]

# File lib/krikri/mapping_dsl.rb, line 20
def properties
  @properties ||= []
end
respond_to_missing?(*) click to toggle source

@return [true] @see method_missing

# File lib/krikri/mapping_dsl.rb, line 27
def respond_to_missing?(*)
  true
end

Private Instance Methods

add_child(name, opts = {}, &block) click to toggle source

Add a ChildDeclaration to this mapping

@param [Symbol] name @param [Hash] opts accepts options; expected options: :class

@return [ChildDeclaration]

# File lib/krikri/mapping_dsl.rb, line 50
def add_child(name, opts = {}, &block)
  delete_property(name)
  properties << ChildDeclaration.new(name, opts.delete(:class), opts, &block)
end
add_property(name, value = nil, &block) click to toggle source

Add a PropertyDeclaration to this mapping

@param [Symbol] name @param [Hash] value ; defaults to nil

@return [ChildDeclaration]

# File lib/krikri/mapping_dsl.rb, line 62
def add_property(name, value = nil, &block)
  delete_property(name)
  properties << PropertyDeclaration.new(name, value, &block)
end
delete_property(name) click to toggle source

Remove a declaration from the property list

@param [Symbol] name the name property whose declarations to remove

# File lib/krikri/mapping_dsl.rb, line 71
def delete_property(name)
  properties.delete_if { |prop| prop.name == name }
end