Class: Rubicante::Environment
- Inherits:
-
Object
- Object
- Rubicante::Environment
- Includes:
- OsFunctions
- Defined in:
- lib/rubicante/environment.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
Instance Method Summary collapse
-
#eval_command(cmd) ⇒ Object
Evaluate a command, sending it off to the appropriate ‘eval_*’ method.
-
#eval_host(cmd) ⇒ Object
Perform polish on a command starting with ‘host’ and evaluate it.
-
#eval_what(cmd) ⇒ Object
Perform polish on a command starting with ‘what’ and evaluate it.
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
- #wrong? ⇒ Boolean (also: #wrong)
Methods included from OsFunctions
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubicante/environment.rb', line 12 def initialize @host = HostGroup.instance @log = Logging::Logger[self] if is_windows? @log.debug "Detected base operating platform is Windows-based" else @log.debug "Detected base operating platform is NON Windows-based" end # Prepare Host logger @appender = Logging::Appender['rubicante'] Logging::Logger['Rubicante::Host'].add_appenders(Logging::Appender['rubicante']) if not @appender.nil? Logging::Logger['Rubicante::Host'].level = @log.level end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
10 11 12 |
# File 'lib/rubicante/environment.rb', line 10 def host @host end |
Instance Method Details
#eval_command(cmd) ⇒ Object
Evaluate a command, sending it off to the appropriate ‘eval_*’ method. Otherwise, through a NotImplementedError
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubicante/environment.rb', line 31 def eval_command(cmd) @log.debug "Received command: #{cmd}" cmd_root = 'eval_' + cmd.split[0].downcase @log.debug "Determined command root to be: #{cmd_root}" if self.respond_to?(cmd_root) self.send(cmd_root, cmd) else raise NotImplementedError end end |
#eval_host(cmd) ⇒ Object
Perform polish on a command starting with ‘host’ and evaluate it
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rubicante/environment.rb', line 46 def eval_host(cmd) @log.debug "Polishing 'host' command" cmd.gsub!(/^[Hh]ost\s([\S]+)\s/, 'host["\1"]') cmd.gsub!(/website\s([^,]+)/, '.website("\1")') cmd.gsub!(/port\s([^,]+)/, '.port(\1)') cmd.gsub!(/service\s([^,]+)/, '.service("\1")') # Clean up some bubble words cmd.gsub!(/listens\son\s/, '') cmd.gsub!(/provides\s/, '') cmd.gsub!(/,/, '') # clean up commas cmd.gsub!(/[\s]/, '') # clean up white space @log.debug "Evaluating polished 'host' command: #{cmd}" instance_eval cmd end |
#eval_what(cmd) ⇒ Object
Perform polish on a command starting with ‘what’ and evaluate it
65 66 67 68 69 70 71 72 73 |
# File 'lib/rubicante/environment.rb', line 65 def eval_what(cmd) @log.debug "Polishing 'what' command" # Clean up some bubble words cmd.gsub!(/^[Ww]hat\s/, '') cmd.gsub!(/is\s/, '') @log.debug "Evaluating polished 'what' command: #{cmd}" instance_eval cmd end |
#wrong? ⇒ Boolean Also known as: wrong
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubicante/environment.rb', line 75 def wrong? @log.debug "Checking environment for things that are wrong" result = [] host.hosts.keys.each do |key| @log.debug "Checking host #{host[key].name}..." result << host[key].wrong? end return result end |