class AbstractMapper::Settings

The configurable container of domain-specific DSL commands and rules along with corresponding AST builder and optimizer

@api private

Attributes

builder[R]

@!attribute [r] builder

@return [Class] The builder class with domain-specific commands

commands[R]

@!attribute [r] commands

@return [AbstractMapper::Commands]

The collection of registered DSL commands
optimizer[R]

@!attribute [r] optimizer

@return [AbstractMapper::Optimizer]

The optimizer with domain-specific rules
rules[R]

@!attribute [r] rules

@return [AbstractMapper::Rules]

The collection of registered optimization rules

Public Class Methods

new(rules = Rules.new, commands = Commands.new, &block) click to toggle source

Initializes a domain-specific settings with commands and rules being set in the block.

@param [Proc] block

@yield the block with settings for commands and rules

# File lib/abstract_mapper/settings.rb, line 46
def initialize(rules = Rules.new, commands = Commands.new, &block)
  @rules    = rules
  @commands = commands
  configure(&block)
  IceNine.deep_freeze(self)
end

Public Instance Methods

update(&block) click to toggle source

Returns a new class with rules and commands added from the block to the existing ones

@return [AbstractMapper::Settings]

@yield the block with settings for commands and rules

# File lib/abstract_mapper/settings.rb, line 60
def update(&block)
  self.class.new(rules, commands, &block)
end

Private Instance Methods

command(name, node, &block) click to toggle source
# File lib/abstract_mapper/settings.rb, line 72
def command(name, node, &block)
  fn = Functions[:subclass?, AST::Node]
  fail Errors::WrongNode.new(node) unless fn[node]
  @commands = commands << [name, node, block]
end
configure(&block) click to toggle source
# File lib/abstract_mapper/settings.rb, line 78
def configure(&block)
  instance_eval(&block) if block_given?
  @builder = Class.new(Builder)
  builder.commands = commands
  @optimizer = Optimizer.new(rules)
end
rule(value) click to toggle source
# File lib/abstract_mapper/settings.rb, line 66
def rule(value)
  fn = Functions[:subclass?, Rules::Base]
  fail Errors::WrongRule.new(value) unless fn[value]
  @rules = rules << value
end