Class: Reacto::Operations::Wrap
- Inherits:
-
Object
- Object
- Reacto::Operations::Wrap
- Defined in:
- lib/reacto/operations/wrap.rb
Instance Method Summary collapse
- #call(tracker) ⇒ Object
-
#initialize(args) ⇒ Wrap
constructor
A new instance of Wrap.
Constructor Details
#initialize(args) ⇒ Wrap
Returns a new instance of Wrap.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/reacto/operations/wrap.rb', line 8 def initialize(args) if args.key?(:value) fail ArgumentError, "'value' is not valid key in the wrapping object" end if args.key?(:error) fail ArgumentError, "'error' is not valid key in the wrapping object" end @args = args end |
Instance Method Details
#call(tracker) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/reacto/operations/wrap.rb', line 20 def call(tracker) value = ->(v) do data = @args.each_with_object({}) do |(key, val), obj| obj[key] = (val.respond_to? :call) ? val.call(v) : val end tracker.on_value OpenStruct.new({ value: v }.merge(data)) end Subscriptions::OperationSubscription.new(tracker, value: value) end |