Class: Yaoc::TransformationCommand
- Inherits:
-
Object
- Object
- Yaoc::TransformationCommand
show all
- Defined in:
- lib/yaoc/transformation_command.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(to: nil, from: nil, fetch_method: nil, conversion_proc: nil, fetcher_proc: nil) ⇒ TransformationCommand
Returns a new instance of TransformationCommand.
30
31
32
33
34
35
36
|
# File 'lib/yaoc/transformation_command.rb', line 30
def initialize(to: nil, from: nil, fetch_method: nil, conversion_proc: nil, fetcher_proc: nil)
self.to = to
self.from = from
self.proc = conversion_proc
self.fetcher = fetch_method
self.value_fetcher_proc = fetcher_proc || ->(to_convert, fetcher, from){ to_convert.public_send(fetcher, from)}
end
|
Class Method Details
.create(to: nil, from: nil, deferred: false, conversion_proc: nil, fetcher_proc: nil) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/yaoc/transformation_command.rb', line 17
def self.create(to: nil, from: nil, deferred: false, conversion_proc: nil, fetcher_proc: nil)
tc_source = deferred ? deferred_source : default_source
-> (to_convert, result){
tc_source.new(to: to, from: from, fetch_method: fetcher, conversion_proc: conversion_proc, fetcher_proc: fetcher_proc).call(to_convert, result)
}
end
|
.default_source ⇒ Object
13
14
15
|
# File 'lib/yaoc/transformation_command.rb', line 13
def self.default_source
TransformationCommand
end
|
.deferred_source ⇒ Object
.fill_result_with_value(result, key, value) ⇒ Object
26
27
28
|
# File 'lib/yaoc/transformation_command.rb', line 26
def self.fill_result_with_value(result, key, value)
result.tap{|taped_result| taped_result[key] = value}
end
|
Instance Method Details
#call(to_convert, result) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/yaoc/transformation_command.rb', line 38
def call(to_convert, result)
unless proc.nil?
instance_exec(to_convert, result, &proc)
else
TransformationCommand.fill_result_with_value(result, to, value(to_convert))
end
end
|
#value(to_convert) ⇒ Object
48
49
50
|
# File 'lib/yaoc/transformation_command.rb', line 48
def value(to_convert)
value_fetcher_proc.call(to_convert, fetcher, from)
end
|