Class: Cardio::Command

Inherits:
Object show all
Includes:
Custom
Defined in:
card/lib/cardio/command.rb,
card/lib/cardio/command/custom.rb,
card/lib/cardio/command/command_base.rb,
card/lib/cardio/command/rake_command.rb,
card/lib/cardio/command/rspec_command.rb,
card/lib/cardio/command/rspec_command/parser.rb

Overview

manage different types of commands that can be run via bin/card (and bin/decko)

Direct Known Subclasses

Commands, Decko::Commands

Defined Under Namespace

Modules: Custom Classes: CommandBase, RakeCommand, RspecCommand

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

TODO: review the following. see if any work well enough to include

application Generate the Rails application code destroy Undo code generated with “generate” (short-cut alias: “d”) benchmarker See how fast a piece of code runs profiler Get profile information from a piece of code plugin Install a plugin jasmine



56
57
58
59
60
61
# File 'card/lib/cardio/command.rb', line 56

def initialize args
  @args = args
  @command = command_for_key args.first&.to_sym
  ENV["PRY_RESCUE_RAILS"] = "1" if rescue?
  @args.shift unless handler == :rails
end

Class Attribute Details

.bin_nameObject

Returns the value of attribute bin_name.



13
14
15
# File 'card/lib/cardio/command.rb', line 13

def bin_name
  @bin_name
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'card/lib/cardio/command.rb', line 10

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



10
11
12
# File 'card/lib/cardio/command.rb', line 10

def command
  @command
end

Class Method Details

.run_non_deck_command(command, commands_script) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'card/lib/cardio/command.rb', line 15

def run_non_deck_command command, commands_script
  if command == "new"
    ARGV.shift
    Cardio::Generators::Deck::DeckGenerator.start
  elsif command.blank?
    require commands_script
  else
    puts "ERROR: `#{bin_name} #{command}` " \
         "cannot be run from outside deck".red
  end
end

Instance Method Details

#gemObject



63
64
65
# File 'card/lib/cardio/command.rb', line 63

def gem
  "card"
end

#mapObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'card/lib/cardio/command.rb', line 28

def map
  @map ||= {
    new: { desc: "create a new deck", group: :shark, via: :call },
    setup: { desc: "populate a database", group: :shark, via: :rake },
    update: { desc: "run data updates", group: :shark, alias: :u, via: :rake },
    version: { desc: "#{gem} gem version", group: :shark, alias: :v, via: :call },
    help: { desc: "show this text", group: :shark, alias: :h, via: :call },

    console: { desc: "start a ruby console", group: :monkey, alias: :c },
    dbconsole: { desc: "start a database console", group: :monkey, alias: :db },
    runner: { desc: "run code in app environment", group: :monkey, alias: :r },
    rspec: { desc: "run rspec tests", group: :monkey, alias: :rs, via: :call },
    generate: { desc: "generate templated code", group: :monkey, alias: :g },
    reset: { desc: "reset cache and tmpfiles", group: :monkey, via: :rake },
    sow: { desc: "export card data to mod yaml", group: :monkey, via: :rake },
    eat: { desc: "ingest card data from mod yaml", group: :monkey, via: :rake }
  }
end

#runObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'card/lib/cardio/command.rb', line 67

def run
  case handler
  when :rails
    run_rails
  when :rake
    run_rake
  when :call
    send "run_#{command}"
  when :unknown
    unknown_error
  end
  exit 0
end