class Reacto::Operations::Act
Constants
- ALL
Public Class Methods
new(action = NO_ACTION, on = ALL)
click to toggle source
# File lib/reacto/operations/act.rb, line 12 def initialize(action = NO_ACTION, on = ALL) @action = action @on = on @on = ALL if @on == :all end
Public Instance Methods
call(tracker)
click to toggle source
# File lib/reacto/operations/act.rb, line 19 def call(tracker) value = if @on.include?(:value) value_action(tracker) else tracker.method(:on_value) end error = if @on.include?(:error) error_action(tracker) else tracker.method(:on_error) end close = if @on.include?(:close) close_action(tracker) else tracker.method(:on_close) end Subscriptions::OperationSubscription.new( tracker, value: value, error: error, close: close ) end
close_action(tracker)
click to toggle source
# File lib/reacto/operations/act.rb, line 60 def close_action(tracker) lambda do @action.call(OpenStruct.new(type: :close)) tracker.on_close end end
error_action(tracker)
click to toggle source
# File lib/reacto/operations/act.rb, line 53 def error_action(tracker) lambda do |error| @action.call(OpenStruct.new(error: error, type: :error)) tracker.on_error(error) end end
value_action(tracker)
click to toggle source
# File lib/reacto/operations/act.rb, line 46 def value_action(tracker) lambda do |value| @action.call(OpenStruct.new(value: value, type: :value)) tracker.on_value(value) end end