Class: Retl::PathBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/retl/path_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, &block) ⇒ PathBuilder

Returns a new instance of PathBuilder.



11
12
13
14
# File 'lib/retl/path_builder.rb', line 11

def initialize(path, &block)
  @path = path
  instance_eval(&block)
end

Instance Method Details

#calculate(key, action = nil, &block) ⇒ Object Also known as: calc



47
48
49
50
# File 'lib/retl/path_builder.rb', line 47

def calculate(key, action=nil, &block)
  action ||= block
  transform { |data, context| data[key] = context.execute_step(action, data) }
end

#depends_on(name, source = nil, &block) ⇒ Object



53
54
55
56
# File 'lib/retl/path_builder.rb', line 53

def depends_on(name, source=nil, &block)
  source ||= block
  @path.add_dependency(name, source)
end

#explode(action = nil, &block) ⇒ Object



58
59
60
61
# File 'lib/retl/path_builder.rb', line 58

def explode(action=nil, &block)
  action ||= block
  step(action, handler: ExplodeHandler)
end

#filter(predicate = nil, &block) ⇒ Object Also known as: select



27
28
29
30
# File 'lib/retl/path_builder.rb', line 27

def filter(predicate=nil, &block)
  predicate ||= block
  step(predicate, handler: FilterHandler)
end

#fork(name, &block) ⇒ Object



33
34
35
# File 'lib/retl/path_builder.rb', line 33

def fork(name, &block)
  @path.add_fork_builder(name, &block)
end

#inspect(action = nil, &block) ⇒ Object



37
38
39
40
# File 'lib/retl/path_builder.rb', line 37

def inspect(action=nil, &block)
  action ||= block
  step(action, handler: InspectHandler)
end

#path(path, dependencies = {}, &block) ⇒ Object



63
64
65
# File 'lib/retl/path_builder.rb', line 63

def path(path, dependencies={}, &block)
  @path.add_handler PathHandler.new(path, dependencies, &block)
end

#reject(predicate = nil, &block) ⇒ Object



42
43
44
45
# File 'lib/retl/path_builder.rb', line 42

def reject(predicate=nil, &block)
  predicate ||= block
  filter { |data, context| !context.execute_step(predicate, data) }
end

#step(step = nil, handler: StepHandler, &block) ⇒ Object Also known as: replace



16
17
18
19
# File 'lib/retl/path_builder.rb', line 16

def step(step=nil, handler: StepHandler, &block)
  step ||= block
  @path.add_step step, handler: handler
end

#transform(action = nil, &block) ⇒ Object



22
23
24
25
# File 'lib/retl/path_builder.rb', line 22

def transform(action=nil, &block)
  action ||= block
  step(action, handler: TransformHandler)
end