class Truth::Client
Client
contains the business logic
Attributes
config[RW]
Public Class Methods
get_command(channel)
click to toggle source
# File lib/truth/client.rb, line 37 def self.get_command(channel) case channel when /add_roles$/ then :add_roles when /remove_roles$/ then :remove_roles when /add_info$/ then :add_info when /remove_info$/ then :remove_info when /set_environment$/ then :set_environment end end
new(config)
click to toggle source
# File lib/truth/client.rb, line 5 def initialize(config) self.config = config end
Public Instance Methods
add_info(message)
click to toggle source
add meta info to be used by your configuration management
# File lib/truth/client.rb, line 66 def add_info(message) key, value = message.split(',', 2) config.add_info key, value.strip end
add_roles(message)
click to toggle source
add an roles array to the roles for this node message is a comma-separated string
# File lib/truth/client.rb, line 51 def add_roles(message) roles = message.split(',').map{|x| x.strip} config.add_roles roles return config.current_roles end
execute_command(channel, message)
click to toggle source
this is the entry point for the client channel can look like: truth-req.hostname.* truth-req.all.*
# File lib/truth/client.rb, line 13 def execute_command(channel, message) begin response = case Client.get_command(channel) when :add_roles add_roles(message) when :remove_roles remove_roles(message) when :add_info add_info(message) when :remove_info remove_info(message) when :set_environment set_environment(message) else puts "no command for #{channel} available" 'NOT AVAILABLE' end rescue Exception => e puts "ERROR: #{e}" response = "ERROR" end response end
remove_info(message)
click to toggle source
# File lib/truth/client.rb, line 71 def remove_info(message) config.remove_info message.strip end
remove_roles(message)
click to toggle source
removes an roles array from the roles for this node. message is a comma-separated string
# File lib/truth/client.rb, line 59 def remove_roles(message) roles = message.split(',').map{|x| x.strip} config.remove_roles roles return config.current_roles end
set_environment(message)
click to toggle source
this can change the environment for this node
# File lib/truth/client.rb, line 76 def set_environment(message) end