Class: FeatureEnvy::Operation
- Inherits:
-
Object
- Object
- FeatureEnvy::Operation
show all
- Defined in:
- lib/feature_envy/operation.rb
Defined Under Namespace
Modules: PipelineOperator
Classes: Pipeline
Constant Summary
collapse
- Placeholder =
Object.new.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args, **kwargs) ⇒ Operation
Returns a new instance of Operation.
63
64
65
66
|
# File 'lib/feature_envy/operation.rb', line 63
def initialize *args, **kwargs
@args = args
@kwargs = kwargs
end
|
Class Method Details
.[] ⇒ Object
60
|
# File 'lib/feature_envy/operation.rb', line 60
def [](...) = self.call(...)
|
.call(*args, **kwargs) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/feature_envy/operation.rb', line 52
def call(*args, **kwargs)
if args.include?(Placeholder) || kwargs.value?(Placeholder)
new(*args, **kwargs)
else
perform(*args, **kwargs)
end
end
|
.define(&block) ⇒ Object
46
47
48
49
50
|
# File 'lib/feature_envy/operation.rb', line 46
def define(&block)
klass = Class.new(Operation)
klass.define_singleton_method(:perform, &block)
klass
end
|
Instance Method Details
#>>(rest) ⇒ Object
88
89
90
|
# File 'lib/feature_envy/operation.rb', line 88
def >>(rest)
Pipeline.new(self, rest)
end
|
#[] ⇒ Object
75
|
# File 'lib/feature_envy/operation.rb', line 75
def [](...) = call(...)
|
#call(value) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/feature_envy/operation.rb', line 68
def call value
args = @args.map { |arg| arg.equal?(Placeholder) ? value : arg }
kwargs = @kwargs.transform_values { |arg| arg.equal?(Placeholder) ? value : arg }
self.class.perform *args, **kwargs
end
|
#inspect ⇒ Object
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/feature_envy/operation.rb', line 77
def inspect
args = []
@args.each do |arg|
args << inspect_arg(arg)
end
kwargs_part = @kwargs.each do |key, arg|
args << "#{key}: #{inspect_arg(arg)}"
end
"#{self.class.name}[#{args.join(", ")}]"
end
|