Class: Populus::Accepter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/populus/accepter.rb

Overview

TODO: validators

Direct Known Subclasses

Event

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#conditionObject

Returns the value of attribute condition.



8
9
10
# File 'lib/populus/accepter.rb', line 8

def condition
  @condition
end

#metadataObject

Returns the value of attribute metadata.



8
9
10
# File 'lib/populus/accepter.rb', line 8

def 
  @metadata
end

#runnerObject

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

Returns:

  • (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