Class: Pears::Provider::Subscription
- Defined in:
- lib/pears/provider/subscription.rb
Overview
Config using redis subscription. This updates automatically upon Redis channel updates. This class would register as “alternative classes with different interfaces”. I ought to clean this up and maybe make “triggers” a different entity from a provider available in the builder.
Instance Attribute Summary collapse
-
#subscription ⇒ Object
readonly
Returns the value of attribute subscription.
Attributes inherited from Base
Instance Method Summary collapse
- #channel ⇒ Object
-
#initialize(channel = nil, redis_host: Pears.config.redis_host, **opts, &fetcher) ⇒ Subscription
constructor
A new instance of Subscription.
- #load_config ⇒ Object
- #purge ⇒ Object
-
#unsubscribe ⇒ Object
This seems a bit “rough” of an approach.
Methods inherited from Base
Constructor Details
#initialize(channel = nil, redis_host: Pears.config.redis_host, **opts, &fetcher) ⇒ Subscription
Returns a new instance of Subscription.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pears/provider/subscription.rb', line 15 def initialize(channel=nil, redis_host: Pears.config.redis_host, **opts, &fetcher) @builder = opts[:builder] || Builder.new(nil) @channel = channel # Fetcher is a "Provider" of some sort. @fetcher = fetcher # Setup redis subscription establish_connection(redis_host) load_config subscribe end |
Instance Attribute Details
#subscription ⇒ Object (readonly)
Returns the value of attribute subscription.
14 15 16 |
# File 'lib/pears/provider/subscription.rb', line 14 def subscription @subscription end |
Instance Method Details
#channel ⇒ Object
31 32 33 |
# File 'lib/pears/provider/subscription.rb', line 31 def channel @channel ||= @builder.subject_name end |
#load_config ⇒ Object
35 36 37 38 39 |
# File 'lib/pears/provider/subscription.rb', line 35 def load_config @builder.freeze_layers do @data = @fetcher.call.data end end |
#purge ⇒ Object
47 48 49 50 |
# File 'lib/pears/provider/subscription.rb', line 47 def purge unsubscribe true end |
#unsubscribe ⇒ Object
This seems a bit “rough” of an approach. we should check if unsubscribing can be done more gracefully.
43 44 45 |
# File 'lib/pears/provider/subscription.rb', line 43 def unsubscribe @subscription.terminate end |