Class: Informer
- Inherits:
-
Object
- Object
- Informer
- Defined in:
- lib/informer.rb
Instance Attribute Summary collapse
-
#watchers ⇒ Object
readonly
Returns the value of attribute watchers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(reporter) ⇒ Informer
constructor
A new instance of Informer.
- #messages ⇒ Object
- #report ⇒ Object
Constructor Details
#initialize(reporter) ⇒ Informer
Returns a new instance of Informer.
15 16 17 18 |
# File 'lib/informer.rb', line 15 def initialize(reporter) @reporter = get_reporter(reporter) @watchers = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/informer.rb', line 45 def method_missing(method, *args, &block) begin watcher = Watcher.const_get("#{method.to_s.camelize}") @watchers << watcher.new(*args, &block) rescue NameError => e puts "No watcher named #{method.to_s}. Error was: #{e}" super end end |
Instance Attribute Details
#watchers ⇒ Object (readonly)
Returns the value of attribute watchers.
13 14 15 |
# File 'lib/informer.rb', line 13 def watchers @watchers end |
Class Method Details
Instance Method Details
#messages ⇒ Object
20 21 22 |
# File 'lib/informer.rb', line 20 def watchers.map {|watcher| watcher.report} end |
#report ⇒ Object
24 25 26 |
# File 'lib/informer.rb', line 24 def report @reporter.report() end |