Class: Reacto::Subscriptions::TrackerSubscription
- Inherits:
-
Object
- Object
- Reacto::Subscriptions::TrackerSubscription
- Includes:
- Subscription
- Defined in:
- lib/reacto/subscriptions/tracker_subscription.rb
Instance Method Summary collapse
- #add(subscription) ⇒ Object
- #add_resource(resource) ⇒ Object
-
#initialize(notification_tracker, trackable) ⇒ TrackerSubscription
constructor
A new instance of TrackerSubscription.
- #on_close ⇒ Object
- #on_error(e) ⇒ Object
- #on_open ⇒ Object
- #on_value(v) ⇒ Object
- #subscribed? ⇒ Boolean
- #unsubscribe ⇒ Object
Constructor Details
#initialize(notification_tracker, trackable) ⇒ TrackerSubscription
Returns a new instance of TrackerSubscription.
8 9 10 11 12 13 14 15 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 8 def initialize(notification_tracker, trackable) @notification_tracker = notification_tracker @trackable = trackable @subscribed = true @subscriptions = [] @resources = [] end |
Instance Method Details
#add(subscription) ⇒ Object
38 39 40 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 38 def add(subscription) @subscriptions << subscription end |
#add_resource(resource) ⇒ Object
34 35 36 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 34 def add_resource(resource) @resources << resource end |
#on_close ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 64 def on_close return unless subscribed? @notification_tracker.on_close @subscriptions.each(&:on_close) unsubscribe end |
#on_error(e) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 56 def on_error(e) return unless subscribed? @notification_tracker.on_error(e) @subscriptions.each { |s| s.on_error(e) } unsubscribe end |
#on_open ⇒ Object
42 43 44 45 46 47 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 42 def on_open return unless subscribed? @notification_tracker.on_open @subscriptions.each(&:on_open) end |
#on_value(v) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 49 def on_value(v) return unless subscribed? @notification_tracker.on_value(v) @subscriptions.each { |s| s.on_value(v) } end |
#subscribed? ⇒ Boolean
17 18 19 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 17 def subscribed? @subscribed end |
#unsubscribe ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/reacto/subscriptions/tracker_subscription.rb', line 21 def unsubscribe @subscriptions.each(&:unsubscribe) return unless subscribed? @trackable.off(@notification_tracker) @trackable = nil @notification_tracker = nil @subscribed = false @resources.each(&:cleanup) @resources = [] end |