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.



9
10
11
12
13
14
15
# File 'lib/retl/transformation.rb', line 9

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

Instance Method Details

#each(&block) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/retl/transformation.rb', line 17

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

#each_slice(size, &block) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/retl/transformation.rb', line 25

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

#errorsObject



57
58
59
# File 'lib/retl/transformation.rb', line 57

def errors
  @errors.each
end

#forks(name) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/retl/transformation.rb', line 34

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



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/retl/transformation.rb', line 43

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