Class: PageMagic::Watcher
- Inherits:
-
Object
- Object
- PageMagic::Watcher
- Defined in:
- lib/page_magic/watcher.rb
Overview
class WatchedElementDefinition - Contains the specification the for checking if an subject has changed
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#==(other) ⇒ Boolen
True of the candiate is equal ot this one.
-
#check(subject = nil) ⇒ Object
check current value of watched element.
-
#initialize(name, method = nil, &block) ⇒ Watcher
constructor
A new instance of Watcher.
Constructor Details
#initialize(name, method = nil, &block) ⇒ Watcher
Returns a new instance of Watcher.
13 14 15 16 17 |
# File 'lib/page_magic/watcher.rb', line 13 def initialize(name, method = nil, &block) @name = name @attribute = method @block = block end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
4 5 6 |
# File 'lib/page_magic/watcher.rb', line 4 def attribute @attribute end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/page_magic/watcher.rb', line 4 def block @block end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
4 5 6 |
# File 'lib/page_magic/watcher.rb', line 4 def last @last end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/page_magic/watcher.rb', line 4 def name @name end |
Instance Method Details
#==(other) ⇒ Boolen
Returns true of the candiate is equal ot this one.
34 35 36 37 38 39 |
# File 'lib/page_magic/watcher.rb', line 34 def ==(other) other.is_a?(Watcher) && name == other.name && attribute == other.attribute && block == other.block end |
#check(subject = nil) ⇒ Object
check current value of watched element. The result of the check is stored against #last a block was specified then this will be executed.
22 23 24 25 26 27 28 29 30 |
# File 'lib/page_magic/watcher.rb', line 22 def check(subject = nil) @last = if block block.call else object = subject.send(name) attribute ? object.send(attribute) : object end self end |