Class: Retl::Transformation

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/retl/transformation.rb

Instance Method Summary collapse

Constructor Details

#initialize(enumerable, path, options = {}) ⇒ Transformation

Returns a new instance of Transformation.



8
9
10
11
12
# File 'lib/retl/transformation.rb', line 8

def initialize(enumerable, path, options={})
  @enumerable, @path, @options = enumerable, path, options
  @context   = Context.new(@path, @options)
  @fork_data = ForkDataCollector.new(@context)
end

Instance Method Details

#each(&block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/retl/transformation.rb', line 14

def each(&block)
  if @each
    @each.each(&block)
  else
    build_each_result(&block)
  end
end

#each_slice(size, &block) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/retl/transformation.rb', line 22

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



31
32
33
34
# File 'lib/retl/transformation.rb', line 31

def forks(name)
  build_each_result
  @path.forks(name).transform(@fork_data.take(name), @options)
end

#load_into(*destinations) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/retl/transformation.rb', line 36

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