Class: Zabby::Runner
- Inherits:
-
Object
- Object
- Zabby::Runner
- Includes:
- Singleton, ShellHelpers
- Defined in:
- lib/zabby/runner.rb
Overview
This is the main interpreter. Additional shell commands are defined in the ShellHelpers module.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
-
#run(command_file = nil, &block) ⇒ Object
Execute script file and/or instruction block.
-
#shell ⇒ Object
Execute an irb like shell in which we can type Zabby commands.
Methods included from ShellHelpers
desc, #help, helpers_doc, #logged_in?, #login, #logout, method_added, #set, #version, #zabbix_classes
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/zabby/runner.rb', line 23 def initialize @config = Zabby::Config.new @connection = Zabby::Connection.new @pure_binding = instance_eval "binding" # Configure Readline for the shell, if available if Object.const_defined?(:Readline) @readline = true Readline.basic_word_break_characters = "" Readline.completion_append_character = nil #Readline.completion_proc = completion_proc $last_res = nil else # Without Readline the Zabby shell is not available. @readline = false end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
21 22 23 |
# File 'lib/zabby/runner.rb', line 21 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
21 22 23 |
# File 'lib/zabby/runner.rb', line 21 def connection @connection end |
Instance Method Details
#run(command_file = nil, &block) ⇒ Object
Execute script file and/or instruction block
45 46 47 48 49 50 51 |
# File 'lib/zabby/runner.rb', line 45 def run(command_file = nil, &block) unless command_file.nil? commands = File.read(command_file) instance_eval(commands, command_file, 1) end instance_eval(&block) if block_given? end |
#shell ⇒ Object
Execute an irb like shell in which we can type Zabby commands.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/zabby/runner.rb', line 54 def shell raise RuntimeError.new("Shell cannot run because 'readline' is missing.") if !@readline puts <<HEADER Zabby Shell #{Zabby::VERSION} ** This is a simple irb like Zabbix Shell. Multiline commands do not work for e.g. ** Type "help" for online documentation. HEADER loop do cmd = Readline.readline('zabby> ') exit(0) if cmd.nil? or cmd == 'exit' next if cmd == "" Readline::HISTORY.push(cmd) execute(cmd) end end |