Class: Dabcup::App

Inherits:
Object
  • Object
show all
Defined in:
lib/dabcup/app.rb

Constant Summary collapse

DABCUP_PATH =
File.expand_path('~/.dabcup')
CONFIG_PATHS =
['dabcup.yml', '~/.dabcup/profiles.yml', '/etc/dabcup/profiles.yml'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_dir) ⇒ App

Returns a new instance of App.



12
13
14
# File 'lib/dabcup/app.rb', line 12

def initialize(app_dir)
  @app_dir = app_dir
end

Instance Attribute Details

#profilesObject (readonly)

Returns the value of attribute profiles.



9
10
11
# File 'lib/dabcup/app.rb', line 9

def profiles
  @profiles
end

Instance Method Details

#help(args) ⇒ Object



42
43
44
# File 'lib/dabcup/app.rb', line 42

def help(args)
  puts Dabcup::Help.message(args[1])
end

#main(args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dabcup/app.rb', line 16

def main(args)
  if args.size < 1
    puts "Try 'dabcup help'."
  elsif ['help', '-h', '--help', '?'].include?(args[0])
    help(args)
  else
    run(args)
  end
#rescue Dabcup::Error => ex
#  $stderr.puts ex.message
#rescue => ex
#  $stderr.puts ex.message
#  $stderr.puts 'See log for more informations.'
#  Dabcup::fatal(ex)
end

#run(args) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/dabcup/app.rb', line 32

def run(args)
  database_name, operation_name = args[0 .. 1]
  raise Dabcup::Error.new("Database '#{database_name}' doesn't exist.") unless config[database_name]
  database = Database.new(database_name, config[database_name])
  operation = Operation.build(operation_name, database)
  operation.run(args)
ensure
  operation.terminate if operation
end