Class: Db2c::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/db2c/run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path('../../../', __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

#gdirObject (readonly)

Returns the value of attribute gdir.



3
4
5
# File 'lib/db2c/run.rb', line 3

def gdir
  @gdir
end

Instance Method Details

#argsObject



44
45
46
# File 'lib/db2c/run.rb', line 44

def args
  @args.join(' ')
end

#autocompleteObject



36
37
38
# File 'lib/db2c/run.rb', line 36

def autocomplete
  "#{@gdir}/lib/autocomplete"
end

#debug?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/db2c/run.rb', line 22

def debug?
  !(@args & %w{-d debug -debug --debug}).empty?
end

#default_dbObject



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 message
  puts "DB2C: #{message}"
  puts "DB2C: #{self.inspect}" if debug?
  exit
end

#filtersObject



40
41
42
# File 'lib/db2c/run.rb', line 40

def filters
  "#{@gdir}/rlwrap/filters"
end

#help?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/db2c/run.rb', line 28

def multiline?
  !(@args & %w{-t}).empty?
end

#nowrap?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/db2c/run.rb', line 25

def nowrap?
  !(@args & %w{--no-rlwrap --now}).empty?
end

#version?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/db2c/run.rb', line 19

def version?
  !(@args & %w{-v version -version --version}).empty?
end

#wordsObject



48
49
50
# File 'lib/db2c/run.rb', line 48

def words
  @args.reject { |arg| arg.start_with?('-') }
end