Class: ApplicationController

Inherits:
Object
  • Object
show all
Defined in:
lib/invoices/controllers/application_controller.rb

Instance Method Summary collapse

Constructor Details

#initializeApplicationController

Returns a new instance of ApplicationController.



17
18
19
20
# File 'lib/invoices/controllers/application_controller.rb', line 17

def initialize
  Schema.new.create_all_tables(INVOICES_DB)
  Dir.mkdir(INVOICES_FOLDER) unless File.directory?(INVOICES_FOLDER)
end

Instance Method Details

#parse_commandsObject



66
67
68
69
70
71
72
# File 'lib/invoices/controllers/application_controller.rb', line 66

def parse_commands
  case ARGV[0]
  when "invoice"
  when "biller"
  when "client"
  end
end

#parse_optionsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/invoices/controllers/application_controller.rb', line 21

def parse_options
  options = {}
  subcommand_help = "\nExamples:\nCreate an invoice: invoices invoice -c 'Client Name'\nCreate a biller:   invoices biller -n\nCreate a client:   invoices client -n"
  @global = OptionParser.new do |opt|
    opt.banner = "Usage: invoices options [subcommand [options]]"
    opt.on("-v", "--version", "Check the version of Invoices") do# |v|
      #options[:version] = v
      puts "v#{INVOICES_VERSION}"
    end
    opt.on("-h", "--help", "Get some help") do# |v|
      #options[:help] = v
      puts @global
      puts subcommand_help
    end
  end
  subcommands = {
    'invoice' => OptionParser.new do |opt|
      opt.on("-c", "--client CLIENT", "Select the client for this invoice") do |v|
        #option[:client] = v
        client = Client.new.find_by_name(v)
        InvoicesController.new(client)
      end
    end,
    'biller' => OptionParser.new do |opt|
      opt.on("-n", "--new", "Add a new biller to the database") do# |v|
        #option[:biller_new] = v
        BillersController.new
      end
    end,
    'client' => OptionParser.new do |opt|
      opt.on("-n", "--new", "Add a new client to the database") do# |v|
        #option[:client_new] = v
        ClientsController.new
      end
    end
  }
  @global.order!
  cmd = ARGV.shift
  if cmd #&& subcommands.key?(cmd.to_sym)
    subcommands[cmd].order!
  else
    puts @global
    puts subcommand_help
  end
end