Class: Capissh::Command::Tree::ConditionBranch::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/capissh/command/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, condition, server) ⇒ Evaluator

Returns a new instance of Evaluator.



49
50
51
52
53
# File 'lib/capissh/command/tree.rb', line 49

def initialize(config, condition, server)
  @configuration = config
  @condition = condition
  @server = server
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/capissh/command/tree.rb', line 63

def method_missing(sym, *args, &block)
  if server.respond_to?(sym)
    server.send(sym, *args, &block)
  elsif configuration.respond_to?(sym)
    configuration.send(sym, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



47
48
49
# File 'lib/capissh/command/tree.rb', line 47

def condition
  @condition
end

#configurationObject (readonly)

Returns the value of attribute configuration.



47
48
49
# File 'lib/capissh/command/tree.rb', line 47

def configuration
  @configuration
end

#serverObject (readonly)

Returns the value of attribute server.



47
48
49
# File 'lib/capissh/command/tree.rb', line 47

def server
  @server
end

Instance Method Details

#in?(role) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/capissh/command/tree.rb', line 55

def in?(role)
  configuration.roles[role].include?(server)
end

#resultObject



59
60
61
# File 'lib/capissh/command/tree.rb', line 59

def result
  eval(condition, binding)
end