Class: Populus::Accepter::Base
- Inherits:
-
Object
- Object
- Populus::Accepter::Base
- Defined in:
- lib/populus/accepter.rb
Overview
TODO: validators
Direct Known Subclasses
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#runner ⇒ Object
Returns the value of attribute runner.
Instance Method Summary collapse
- #accept(data) ⇒ Object
-
#initialize(cond: nil, runs: nil, metadata: {}) ⇒ Base
constructor
A new instance of Base.
- #on(hostname, &run_it) ⇒ Object
- #type?(t) ⇒ Boolean
Constructor Details
#initialize(cond: nil, runs: nil, metadata: {}) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 |
# File 'lib/populus/accepter.rb', line 10 def initialize(cond: nil, runs: nil, metadata: {}) self.condition = cond self.runner = runs self. = end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
8 9 10 |
# File 'lib/populus/accepter.rb', line 8 def condition @condition end |
#metadata ⇒ Object
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/populus/accepter.rb', line 8 def @metadata end |
#runner ⇒ Object
Returns the value of attribute runner.
8 9 10 |
# File 'lib/populus/accepter.rb', line 8 def runner @runner end |
Instance Method Details
#accept(data) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/populus/accepter.rb', line 23 def accept(data) if condition[data] Populus.logger.debug "Condition judged true: #{data.inspect}" instance_exec(data, &runner) return true else Populus.logger.debug "Condition judged false: #{data.inspect}" return false end end |
#on(hostname, &run_it) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/populus/accepter.rb', line 34 def on(hostname, &run_it) be = Node.registry[hostname] if be RemoteRunner.new(be, &run_it) else Populus.logger.warn "Not found host: #{hostname}. Skip." end end |
#type?(t) ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/populus/accepter.rb', line 16 def type?(t) current_type = self.class.name.downcase .split('::') .last current_type == t end |