Class: AbstractMapper

Inherits:
Object
  • Object
show all
Extended by:
DSL
Defined in:
lib/abstract_mapper.rb,
lib/abstract_mapper/dsl.rb,
lib/abstract_mapper/node.rb,
lib/abstract_mapper/rule.rb,
lib/abstract_mapper/rules.rb,
lib/abstract_mapper/branch.rb,
lib/abstract_mapper/builder.rb,
lib/abstract_mapper/command.rb,
lib/abstract_mapper/commands.rb,
lib/abstract_mapper/settings.rb,
lib/abstract_mapper/functions.rb,
lib/abstract_mapper/optimizer.rb,
lib/abstract_mapper/pair_rule.rb,
lib/abstract_mapper/sole_rule.rb,
lib/abstract_mapper/attributes.rb,
lib/abstract_mapper/errors/wrong_node.rb,
lib/abstract_mapper/errors/wrong_rule.rb,
lib/abstract_mapper/errors/unknown_command.rb

Overview

The configurable base class for mappers

The mapper DSL is configured by assigning it a specific settings:

class BaseMapper < AbstractMapper::Mapper
  configure do
    command :list, List     # domain-specific command
    command :rename, Rename # domain-specific command

    rule MergeLists         # domain-specific rule
  end
end

Then a configured mapper can use a corresponding DSL commands

class ConcreteMapper < BaseMapper
  list do
    rename :foo, to: :bar
  end
end

Defined Under Namespace

Modules: Attributes, DSL, Errors, Functions Classes: Branch, Builder, Command, Commands, Node, Optimizer, PairRule, Rule, Rules, Settings, SoleRule

Instance Attribute Summary collapse

Attributes included from DSL

#settings

Class Method Summary collapse

Methods included from DSL

configure, finalize, inherited

Instance Attribute Details

#treeAbstractMapper::Branch (readonly)

Returns AST.

Returns:



59
60
61
# File 'lib/abstract_mapper.rb', line 59

def tree
  @tree
end

Class Method Details

.call(input) ⇒ Object

Maps the input data to some output using the transformation, described by the optimized [#tree]

Parameters:

  • input (Object)

Returns:

  • (Object)


81
82
83
# File 'lib/abstract_mapper.rb', line 81

def call(input)
  @transproc.call(input)
end

.initializeObject



68
69
70
71
72
# File 'lib/abstract_mapper.rb', line 68

def initialize
  @tree = self.class.finalize
  @transproc = @tree.transproc
  IceNine.deep_freeze(self)
end

.newAbstractMapper::Mapper

Creates a mapper instance with the optimized AST

Returns:

  • (AbstractMapper::Mapper)


# File 'lib/abstract_mapper.rb', line 61