Class: Cardio::Commands::RakeCommand::Parser

Inherits:
OptionParser
  • Object
show all
Defined in:
card/lib/cardio/commands/rake_command/parser.rb

Overview

parse decko/card -specific options for rake

Constant Summary collapse

ONS =
{
  production: {
    desc: "production database (default)"
  },
  test: {},
  development: {},
  all: {
    desc: "production, test, and development database",
    envs: %w[production development test]
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(command, opts) ⇒ Parser

Returns a new instance of Parser.



22
23
24
25
26
27
28
29
30
31
# File 'card/lib/cardio/commands/rake_command/parser.rb', line 22

def initialize command, opts
  super() do |parser|
    parser.banner = "Usage: decko #{command} [options]\n\n" \
                    "Run decko:#{command} task on the production "\
                    " database specified in config/database.yml\n\n"
    parser_ons parser, command do |env_array|
      opts[:envs] = env_array
    end
  end
end

Instance Method Details

#parser_on_opts(env, command, desc) ⇒ Object



41
42
43
44
45
46
# File 'card/lib/cardio/commands/rake_command/parser.rb', line 41

def parser_on_opts env, command, desc
  main = "--#{env}"
  short = "-#{env.to_s[0]}"
  desc ||= "#{env} database"
  [main, short, "#{command} #{desc}"]
end

#parser_ons(parser, command) ⇒ Object



33
34
35
36
37
38
39
# File 'card/lib/cardio/commands/rake_command/parser.rb', line 33

def parser_ons parser, command
  ONS.each do |env, vals|
    parser.on(*parser_on_opts(env, command, vals[:desc])) do
      yield (vals[:envs] || [env.to_s])
    end
  end
end