Class: Retl::PathBuilder
- Inherits:
-
Object
- Object
- Retl::PathBuilder
- Defined in:
- lib/retl/path_builder.rb
Instance Method Summary collapse
- #calculate(key, action = nil, &block) ⇒ Object (also: #calc)
- #depends_on(name, source = nil, &block) ⇒ Object
- #desc(step_description) ⇒ Object
- #explode(action = nil, &block) ⇒ Object
- #filter(predicate = nil, &block) ⇒ Object (also: #select)
- #fork(name, &block) ⇒ Object
-
#initialize(path, &block) ⇒ PathBuilder
constructor
A new instance of PathBuilder.
- #inspect(action = nil, &block) ⇒ Object
- #path(path, dependencies = {}, &block) ⇒ Object
- #reject(predicate = nil, &block) ⇒ Object
- #step(step = nil, handler: StepHandler, &block) ⇒ Object (also: #replace)
- #transform(action = nil, &block) ⇒ Object
Constructor Details
#initialize(path, &block) ⇒ PathBuilder
Returns a new instance of PathBuilder.
12 13 14 15 16 |
# File 'lib/retl/path_builder.rb', line 12 def initialize(path, &block) @path = path @next_descripion = NextDescription.new instance_eval(&block) end |
Instance Method Details
#calculate(key, action = nil, &block) ⇒ Object Also known as: calc
53 54 55 56 |
# File 'lib/retl/path_builder.rb', line 53 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
59 60 61 62 |
# File 'lib/retl/path_builder.rb', line 59 def depends_on(name, source=nil, &block) source ||= block @path.add_dependency(name, source) end |
#desc(step_description) ⇒ Object
73 74 75 |
# File 'lib/retl/path_builder.rb', line 73 def desc(step_description) @next_descripion.describe_next(step_description) end |
#explode(action = nil, &block) ⇒ Object
64 65 66 67 |
# File 'lib/retl/path_builder.rb', line 64 def explode(action=nil, &block) action ||= block step(action, handler: ExplodeHandler) end |
#filter(predicate = nil, &block) ⇒ Object Also known as: select
33 34 35 36 |
# File 'lib/retl/path_builder.rb', line 33 def filter(predicate=nil, &block) predicate ||= block step(predicate, handler: FilterHandler) end |
#fork(name, &block) ⇒ Object
39 40 41 |
# File 'lib/retl/path_builder.rb', line 39 def fork(name, &block) @path.add_fork_builder(name, &block) end |
#inspect(action = nil, &block) ⇒ Object
43 44 45 46 |
# File 'lib/retl/path_builder.rb', line 43 def inspect(action=nil, &block) action ||= block step(action, handler: InspectHandler) end |
#path(path, dependencies = {}, &block) ⇒ Object
69 70 71 |
# File 'lib/retl/path_builder.rb', line 69 def path(path, dependencies={}, &block) @path.add_handler PathHandler.new(path, dependencies, &block) end |
#reject(predicate = nil, &block) ⇒ Object
48 49 50 51 |
# File 'lib/retl/path_builder.rb', line 48 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
18 19 20 21 22 23 24 25 |
# File 'lib/retl/path_builder.rb', line 18 def step(step=nil, handler: StepHandler, &block) step ||= block handler = handler.new(step) handler.description = @next_descripion.take @path.add_handler handler end |
#transform(action = nil, &block) ⇒ Object
28 29 30 31 |
# File 'lib/retl/path_builder.rb', line 28 def transform(action=nil, &block) action ||= block step(action, handler: TransformHandler) end |