class Transformator::Transformation

Attributes

source[RW]
target[RW]

Public Class Methods

call(*args) click to toggle source
# File lib/transformator/transformation.rb, line 20
def self.call(*args)
  new.call(*args)
end
new() click to toggle source
# File lib/transformator/transformation.rb, line 31
def initialize
  # steps are instanced once, which means that instance variables retain
  @steps = self.class.steps.flatten.map do |_step|
    _step.is_a?(Class) ? _step.new(self) : _step
  end
end
require_directory(directory) click to toggle source

since a transformation can have many steps, writing a “require” for each is tedious

# File lib/transformator/transformation.rb, line 25
def self.require_directory(directory)
  Dir.glob("#{File.expand_path(directory)}/*.rb").each do |_filename|
    require _filename
  end
end
sequence(value = nil)
Alias for: steps
steps(value = nil) click to toggle source
# File lib/transformator/transformation.rb, line 10
def steps(value = nil)
  unless value
    @steps
  else
    @steps = value
  end
end
Also aliased as: sequence

Public Instance Methods

call(source, options = {}) click to toggle source
# File lib/transformator/transformation.rb, line 38
def call(source, options = {})
  @source = source
  @target = (options || {})[:target]

  @steps.each do |_step|
    _step.is_a?(Proc) ? instance_exec(&_step) : _step.call
  end

  return @target
end