Class: AbstractMapper

Inherits:
Object
  • Object
show all
Extended by:
DSL
Defined in:
lib/abstract_mapper.rb,
lib/abstract_mapper/ast.rb,
lib/abstract_mapper/dsl.rb,
lib/abstract_mapper/rules.rb,
lib/abstract_mapper/errors.rb,
lib/abstract_mapper/builder.rb,
lib/abstract_mapper/ast/node.rb,
lib/abstract_mapper/commands.rb,
lib/abstract_mapper/settings.rb,
lib/abstract_mapper/functions.rb,
lib/abstract_mapper/optimizer.rb,
lib/abstract_mapper/ast/branch.rb,
lib/abstract_mapper/rules/base.rb,
lib/abstract_mapper/rules/pair.rb,
lib/abstract_mapper/rules/sole.rb,
lib/abstract_mapper/commands/base.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: AST, DSL, Errors, Functions Classes: Builder, Commands, Optimizer, Rules, Settings

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:

  • (AbstractMapper::Branch)

    AST



48
49
50
# File 'lib/abstract_mapper.rb', line 48

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)


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

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

.initializeObject



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

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 50