Class: Feedbook::Notification
- Inherits:
-
Object
- Object
- Feedbook::Notification
- Defined in:
- lib/feedbook/notification.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ type
constructor
Initializes Notification instance.
-
#notify(object) ⇒ NilClass
Notifies selected gateway about new post.
-
#valid? ⇒ NilClass
Validates if given parameters are valid.
Constructor Details
#initialize(opts = {}) ⇒ type
Initializes Notification instance
16 17 18 19 20 |
# File 'lib/feedbook/notification.rb', line 16 def initialize(opts = {}) @type = opts.fetch(:type, '') @variables = opts.fetch(:variables, {}) @template = parse_template(opts.fetch(:template, '')) end |
Instance Attribute Details
#template ⇒ Object (readonly)
Returns the value of attribute template.
10 11 12 |
# File 'lib/feedbook/notification.rb', line 10 def template @template end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/feedbook/notification.rb', line 10 def type @type end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
10 11 12 |
# File 'lib/feedbook/notification.rb', line 10 def variables @variables end |
Instance Method Details
#notify(object) ⇒ NilClass
Notifies selected gateway about new post
26 27 28 29 30 |
# File 'lib/feedbook/notification.rb', line 26 def notify(object) = template.render(object.to_hash.merge(variables)) notifier.notify() end |
#valid? ⇒ NilClass
Validates if given parameters are valid
36 37 38 39 40 |
# File 'lib/feedbook/notification.rb', line 36 def valid? unless variables.is_a? Hash raise Errors::InvalidVariablesFormatError.new end end |