Class: Reactor::Subscription
- Inherits:
-
Object
- Object
- Reactor::Subscription
- Defined in:
- lib/reactor/subscription.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#deprecated ⇒ Object
readonly
Returns the value of attribute deprecated.
-
#event_name ⇒ Object
readonly
Returns the value of attribute event_name.
-
#handler_name ⇒ Object
readonly
Returns the value of attribute handler_name.
-
#sidekiq_options ⇒ Object
readonly
Returns the value of attribute sidekiq_options.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#worker_class ⇒ Object
readonly
Returns the value of attribute worker_class.
Class Method Summary collapse
Instance Method Summary collapse
- #event_handler_names ⇒ Object
- #generate_namespace ⇒ Object
- #handler_defined? ⇒ Boolean
-
#initialize(options = {}, &block) ⇒ Subscription
constructor
A new instance of Subscription.
- #mailer_subscriber? ⇒ Boolean
- #namespace ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Subscription
Returns a new instance of Subscription.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/reactor/subscription.rb', line 17 def initialize( = {}, &block) @source = [:source] @handler_name = self.class.build_handler_name( [:event_name], [:handler_name] ) @event_name = [:event_name] @action = [:action] || block @delay = [:delay].to_i @deprecated = !![:deprecated] @sidekiq_options = [:sidekiq_options] || {} build_worker_class end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
4 5 6 |
# File 'lib/reactor/subscription.rb', line 4 def action @action end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
4 5 6 |
# File 'lib/reactor/subscription.rb', line 4 def delay @delay end |
#deprecated ⇒ Object (readonly)
Returns the value of attribute deprecated.
4 5 6 |
# File 'lib/reactor/subscription.rb', line 4 def deprecated @deprecated end |
#event_name ⇒ Object (readonly)
Returns the value of attribute event_name.
4 5 6 |
# File 'lib/reactor/subscription.rb', line 4 def event_name @event_name end |
#handler_name ⇒ Object (readonly)
Returns the value of attribute handler_name.
4 5 6 |
# File 'lib/reactor/subscription.rb', line 4 def handler_name @handler_name end |
#sidekiq_options ⇒ Object (readonly)
Returns the value of attribute sidekiq_options.
4 5 6 |
# File 'lib/reactor/subscription.rb', line 4 def @sidekiq_options end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/reactor/subscription.rb', line 4 def source @source end |
#worker_class ⇒ Object (readonly)
Returns the value of attribute worker_class.
4 5 6 |
# File 'lib/reactor/subscription.rb', line 4 def worker_class @worker_class end |
Class Method Details
.build_handler_name(event_name, handler_name_option = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/reactor/subscription.rb', line 7 def self.build_handler_name(event_name, handler_name_option = nil) if handler_name_option handler_name_option.to_s.camelize elsif event_name == '*' 'WildcardHandler' else "#{event_name.to_s.camelize}Handler" end end |
Instance Method Details
#event_handler_names ⇒ Object
37 38 39 |
# File 'lib/reactor/subscription.rb', line 37 def event_handler_names @event_handler_names ||= [] end |
#generate_namespace ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/reactor/subscription.rb', line 46 def generate_namespace module_chain.reduce(Reactor.subscriber_namespace) do |mod, name| unless mod.const_defined?(name, false) mod.const_set(name, Module.new) end mod.const_get(name) end end |
#handler_defined? ⇒ Boolean
32 33 34 35 |
# File 'lib/reactor/subscription.rb', line 32 def handler_defined? namespace.const_defined?(handler_name) && namespace.const_get(handler_name).parents.include?(Reactor.subscriber_namespace) end |
#mailer_subscriber? ⇒ Boolean
55 56 57 |
# File 'lib/reactor/subscription.rb', line 55 def mailer_subscriber? !!(source < ActionMailer::Base) end |
#namespace ⇒ Object
41 42 43 44 |
# File 'lib/reactor/subscription.rb', line 41 def namespace return @namespace if @namespace @namespace = generate_namespace end |