Class: Transformator::Transformation::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/transformator/transformation/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transformation = nil, options = {}) ⇒ Step

Returns a new instance of Step.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/transformator/transformation/step.rb', line 6

def initialize(transformation = nil, options = {})
  if transformation.is_a?(Hash)
    options = transformation
    transformation = nil
  end

  if transformation
    @transformation = transformation
  else
    @transformation = Struct.new(:source, :target).new.tap do |_struct|
      _struct.source = options[:source]
      _struct.target = options[:target]
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Each step has transparent access to all methods of it’s transformation



28
29
30
31
32
33
34
# File 'lib/transformator/transformation/step.rb', line 28

def method_missing(method_name, *args, &block)
  if @transformation.respond_to?(method_name)
    @transformation.send(method_name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#transformationObject

Returns the value of attribute transformation.



4
5
6
# File 'lib/transformator/transformation/step.rb', line 4

def transformation
  @transformation
end

Instance Method Details

#callObject



22
23
# File 'lib/transformator/transformation/step.rb', line 22

def call
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/transformator/transformation/step.rb', line 36

def respond_to_missing?(method_name, include_private = false)
  @transformation.respond_to?(method_name) || super
end

#sourceObject

avoid method_missing penalty for the most used transformation methods



41
# File 'lib/transformator/transformation/step.rb', line 41

def source;         @transformation.source;         end

#source=(value) ⇒ Object



42
# File 'lib/transformator/transformation/step.rb', line 42

def source=(value); @transformation.source=(value); end

#targetObject



43
# File 'lib/transformator/transformation/step.rb', line 43

def target;         @transformation.target;         end

#target=(value) ⇒ Object



44
# File 'lib/transformator/transformation/step.rb', line 44

def target=(value); @transformation.target=(value); end