Class: Noticent::Definitions::Channel
- Inherits:
-
Object
- Object
- Noticent::Definitions::Channel
- Defined in:
- lib/noticent/definitions/channel.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(config, name, group: :default, klass: nil) ⇒ Channel
constructor
A new instance of Channel.
- #instance(config, recipients, payload, context) ⇒ Object
- #using(options = {}) ⇒ Object
Constructor Details
#initialize(config, name, group: :default, klass: nil) ⇒ Channel
Returns a new instance of Channel.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/noticent/definitions/channel.rb', line 11 def initialize(config, name, group: :default, klass: nil) raise BadConfiguration, 'name should be a symbol' unless name.is_a? Symbol raise BadConfiguration, '\'_any_\' is a reserved channel name' if name == :_any_ raise BadConfiguration, '\'_none_\' is a reserved channel name' if name == :_none_ @name = name @group = group @config = config sub_module = @config.use_sub_modules ? '::Channels::' : '::' suggested_class_name = @config.base_module_name + sub_module + name.to_s.camelize @klass = klass.nil? ? suggested_class_name.camelize.constantize : klass rescue NameError raise Noticent::BadConfiguration, "no class found for #{suggested_class_name}" end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
7 8 9 |
# File 'lib/noticent/definitions/channel.rb', line 7 def group @group end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
8 9 10 |
# File 'lib/noticent/definitions/channel.rb', line 8 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/noticent/definitions/channel.rb', line 6 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/noticent/definitions/channel.rb', line 9 def @options end |
Instance Method Details
#instance(config, recipients, payload, context) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/noticent/definitions/channel.rb', line 32 def instance(config, recipients, payload, context) inst = @klass.new(config, recipients, payload, context) return inst if @options.nil? || @options.empty? @options.each do |k, v| inst.send("#{k}=", v) rescue NoMethodError raise Noticent::BadConfiguration, "no method #{k}= found on #{@klass} as it is defined with the `using` clause" end inst rescue ArgumentError raise Noticent::BadConfiguration, "channel #{@klass} initializer arguments are mismatching." end |
#using(options = {}) ⇒ Object
28 29 30 |
# File 'lib/noticent/definitions/channel.rb', line 28 def using( = {}) @options = end |