Class: Retl::Transformation
- Inherits:
-
Object
- Object
- Retl::Transformation
- Includes:
- Enumerable
- Defined in:
- lib/retl/transformation.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #each_slice(size, &block) ⇒ Object
- #forks(name) ⇒ Object
-
#initialize(enumerable, path, options = {}) ⇒ Transformation
constructor
A new instance of Transformation.
- #load_into(*destinations) ⇒ Object
Constructor Details
#initialize(enumerable, path, options = {}) ⇒ Transformation
Returns a new instance of Transformation.
8 9 10 11 12 13 |
# File 'lib/retl/transformation.rb', line 8 def initialize(enumerable, path, ={}) @enumerable, @path, @options = enumerable, path, @context = Context.new(@path, @options) @fork_data = ForkDataCollector.new(@context) @forks = {} end |
Instance Method Details
#each(&block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/retl/transformation.rb', line 15 def each(&block) if @each @each.each(&block) else build_each_result(&block) end end |
#each_slice(size, &block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/retl/transformation.rb', line 23 def each_slice(size, &block) @each_slice ||= {} if @each_slice[size] @each_slice[size].each(&block) else build_each_slice_result(size, &block) end end |
#forks(name) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/retl/transformation.rb', line 32 def forks(name) unless @forks[name] build_each_result @forks[name] = @path.forks(name).transform(@fork_data.take(name), @options) end @forks[name] end |
#load_into(*destinations) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/retl/transformation.rb', line 41 def load_into(*destinations) destinations = Array(destinations) each do |data| destinations.each do |destination| destination << data end end destinations.each do |destination| destination.close if destination.respond_to?(:close) end end |