Class: Observational::Observer
- Inherits:
-
Object
- Object
- Observational::Observer
- Defined in:
- lib/observational/observer.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#observed_attrs ⇒ Object
readonly
Returns the value of attribute observed_attrs.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#subscriber ⇒ Object
readonly
Returns the value of attribute subscriber.
Instance Method Summary collapse
-
#initialize(options) ⇒ Observer
constructor
A new instance of Observer.
-
#invoke(observable) ⇒ Object
Check the observed attrbiutes, and return of they have not changed.
- #observes_action?(action) ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Observer
Returns a new instance of Observer.
5 6 7 8 9 10 11 |
# File 'lib/observational/observer.rb', line 5 def initialize() @subscriber = [:subscriber] @method = [:method] @parameters = [:parameters] @actions = [*[:actions]] @observed_attrs = [:observed_attrs] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
3 4 5 |
# File 'lib/observational/observer.rb', line 3 def actions @actions end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/observational/observer.rb', line 3 def method @method end |
#observed_attrs ⇒ Object (readonly)
Returns the value of attribute observed_attrs.
3 4 5 |
# File 'lib/observational/observer.rb', line 3 def observed_attrs @observed_attrs end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
3 4 5 |
# File 'lib/observational/observer.rb', line 3 def parameters @parameters end |
#subscriber ⇒ Object (readonly)
Returns the value of attribute subscriber.
3 4 5 |
# File 'lib/observational/observer.rb', line 3 def subscriber @subscriber end |
Instance Method Details
#invoke(observable) ⇒ Object
Check the observed attrbiutes, and return of they have not changed
14 15 16 17 |
# File 'lib/observational/observer.rb', line 14 def invoke(observable) return if (observable.changed & self.observed_attrs).blank? @subscriber.send(method, *arguments(observable)) end |
#observes_action?(action) ⇒ Boolean
19 20 21 |
# File 'lib/observational/observer.rb', line 19 def observes_action?(action) actions.include?(action.to_sym) end |