Class: Db2c::Run
- Inherits:
-
Object
- Object
- Db2c::Run
- Defined in:
- lib/db2c/run.rb
Instance Attribute Summary collapse
-
#gdir ⇒ Object
readonly
Returns the value of attribute gdir.
Instance Method Summary collapse
- #args ⇒ Object
- #autocomplete ⇒ Object
- #debug? ⇒ Boolean
- #default_db ⇒ Object
- #die(message) ⇒ Object
- #filters ⇒ Object
- #help? ⇒ Boolean
-
#initialize(*args) ⇒ Run
constructor
A new instance of Run.
- #multiline? ⇒ Boolean
- #nowrap? ⇒ Boolean
- #version? ⇒ Boolean
- #words ⇒ Object
Constructor Details
#initialize(*args) ⇒ Run
Returns a new instance of Run.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/db2c/run.rb', line 5 def initialize *args @args = args puts "args: #{@args.inspect}" if debug? @gdir = File.('../../../', __FILE__) puts "cdir: #{@gdir.inspect}" if debug? die "version #{Db2c::VERSION}" if version? die "The db2 command was not found!" unless system("which db2 > /dev/null 2> /dev/null") die "This program depends on rlwrap, please install rlwrap" unless nowrap? || system("which rlwrap > /dev/null 2> /dev/null") end |
Instance Attribute Details
#gdir ⇒ Object (readonly)
Returns the value of attribute gdir.
3 4 5 |
# File 'lib/db2c/run.rb', line 3 def gdir @gdir end |
Instance Method Details
#args ⇒ Object
44 45 46 |
# File 'lib/db2c/run.rb', line 44 def args @args.join(' ') end |
#autocomplete ⇒ Object
36 37 38 |
# File 'lib/db2c/run.rb', line 36 def autocomplete "#{@gdir}/lib/autocomplete" end |
#debug? ⇒ Boolean
22 23 24 |
# File 'lib/db2c/run.rb', line 22 def debug? !(@args & %w{-d debug -debug --debug}).empty? end |
#default_db ⇒ Object
32 33 34 |
# File 'lib/db2c/run.rb', line 32 def default_db words.first if words.length == 1 && words.first !~ /(help|man|debug|version)/ end |
#die(message) ⇒ Object
52 53 54 55 56 |
# File 'lib/db2c/run.rb', line 52 def die puts "DB2C: #{}" puts "DB2C: #{self.inspect}" if debug? exit end |
#filters ⇒ Object
40 41 42 |
# File 'lib/db2c/run.rb', line 40 def filters "#{@gdir}/rlwrap/filters" end |
#help? ⇒ Boolean
16 17 18 |
# File 'lib/db2c/run.rb', line 16 def help? !(@args & %w{-h help -help --help man --man}).empty? end |
#multiline? ⇒ Boolean
28 29 30 |
# File 'lib/db2c/run.rb', line 28 def multiline? !(@args & %w{-t}).empty? end |
#nowrap? ⇒ Boolean
25 26 27 |
# File 'lib/db2c/run.rb', line 25 def nowrap? !(@args & %w{--no-rlwrap --now}).empty? end |
#version? ⇒ Boolean
19 20 21 |
# File 'lib/db2c/run.rb', line 19 def version? !(@args & %w{-v version -version --version}).empty? end |
#words ⇒ Object
48 49 50 |
# File 'lib/db2c/run.rb', line 48 def words @args.reject { |arg| arg.start_with?('-') } end |