Class: Transformator::Transformation
- Inherits:
-
Object
- Object
- Transformator::Transformation
- Defined in:
- lib/transformator/transformation.rb
Defined Under Namespace
Classes: Step
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
- .call(*args) ⇒ Object
-
.require_directory(directory) ⇒ Object
since a transformation can have many steps, writing a “require” for each is tedious.
- .steps(value = nil) ⇒ Object (also: sequence)
Instance Method Summary collapse
- #call(source, options = {}) ⇒ Object
-
#initialize ⇒ Transformation
constructor
A new instance of Transformation.
Constructor Details
#initialize ⇒ Transformation
31 32 33 34 35 36 |
# 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 |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/transformator/transformation.rb', line 6 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
7 8 9 |
# File 'lib/transformator/transformation.rb', line 7 def target @target end |
Class Method Details
.call(*args) ⇒ Object
20 21 22 |
# File 'lib/transformator/transformation.rb', line 20 def self.call(*args) new.call(*args) end |
.require_directory(directory) ⇒ Object
since a transformation can have many steps, writing a “require” for each is tedious
25 26 27 28 29 |
# File 'lib/transformator/transformation.rb', line 25 def self.require_directory(directory) Dir.glob("#{File.(directory)}/*.rb").each do |_filename| require _filename end end |
.steps(value = nil) ⇒ Object Also known as: sequence
10 11 12 13 14 15 16 |
# File 'lib/transformator/transformation.rb', line 10 def steps(value = nil) unless value @steps else @steps = value end end |
Instance Method Details
#call(source, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/transformator/transformation.rb', line 38 def call(source, = {}) @source = source @target = ( || {})[:target] @steps.each do |_step| _step.is_a?(Proc) ? instance_exec(&_step) : _step.call end return @target end |