Class: Oci8Simple::Cli
- Inherits:
-
Object
- Object
- Oci8Simple::Cli
- Includes:
- Command
- Defined in:
- lib/oci8_simple/cli.rb
Overview
Description
A very thin wrapper around Oci8Simple::Client that handles ARGV / options and formats the output in a manner suitable for printing on the console
Usage
cli = Oci8Simple::Cli.new
cli.run "select id, name from foos" # "3, Bacon\n5, Cheese Puffs\n..."
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#env ⇒ Object
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #format(arr, options) ⇒ Object
-
#initialize(env = nil) ⇒ Cli
constructor
A new instance of Cli.
- #run(sql, options = {}) ⇒ Object
Methods included from Command
Constructor Details
#initialize(env = nil) ⇒ Cli
Returns a new instance of Cli.
13 14 15 |
# File 'lib/oci8_simple/cli.rb', line 13 def initialize(env=nil) self.env = env end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
11 12 13 |
# File 'lib/oci8_simple/cli.rb', line 11 def client @client end |
#env ⇒ Object
Returns the value of attribute env.
11 12 13 |
# File 'lib/oci8_simple/cli.rb', line 11 def env @env end |
Class Method Details
.run_from_argv ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/oci8_simple/cli.rb', line 37 def self.run_from_argv o = (self.usage) if(ARGV[0].nil?) puts o else puts self.new(@options[:environment]).run(ARGV[0], @options) end end |
.usage ⇒ Object
33 34 35 |
# File 'lib/oci8_simple/cli.rb', line 33 def self.usage "Usage: #{$0} [-e ENV] \"SQL\"" end |
Instance Method Details
#format(arr, options) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/oci8_simple/cli.rb', line 21 def format(arr, ) if([:hash]) arr.map{|row| row.map{|k,v| "#{k}: #{v}"}.join("\n")}.join("\n\n") else arr.map{|row| row.join(", ")}.join("\n") end end |
#run(sql, options = {}) ⇒ Object
17 18 19 |
# File 'lib/oci8_simple/cli.rb', line 17 def run(sql, ={}) format(client.run(sql, ), ) end |