Class: Cardio::Commands
- Inherits:
-
Object
- Object
- Cardio::Commands
- Extended by:
- Accessors
- Defined in:
- lib/cardio/commands.rb,
lib/cardio/commands/command.rb,
lib/cardio/commands/rake_command.rb,
lib/cardio/commands/rspec_command.rb,
lib/cardio/commands/rake_command/parser.rb,
lib/cardio/commands/rspec_command/parser.rb
Overview
manage different types of commands that can be run via bin/card and bin/decko
Defined Under Namespace
Modules: Accessors Classes: Command, RakeCommand, RspecCommand
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
- #handler ⇒ Object
-
#initialize(args) ⇒ Commands
constructor
A new instance of Commands.
- #rake_prefix ⇒ Object
- #rescue? ⇒ Boolean
- #run ⇒ Object
-
#run_help ⇒ Object
~~~~~~~~~ CUSTOM COMMANDS ~~~~~~~~~~~~ #.
- #run_jasmine ⇒ Object
- #run_new ⇒ Object
-
#run_rails ⇒ Object
runs all commands in “rails” list.
-
#run_rake ⇒ Object
runs all commands in “rake” list.
- #run_rspec ⇒ Object
- #run_version ⇒ Object
-
#unrecognized ⇒ Object
~~~~~~~~~~~~~~~~~~~~~ catch-all ————– #.
Methods included from Accessors
Constructor Details
#initialize(args) ⇒ Commands
Returns a new instance of Commands.
37 38 39 40 41 42 |
# File 'lib/cardio/commands.rb', line 37 def initialize args @args = args @command = self.class.aliases[args.first] || args.first ENV["PRY_RESCUE_RAILS"] = "1" if rescue? @args.shift unless handler == :rails end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/cardio/commands.rb', line 6 def args @args end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/cardio/commands.rb', line 6 def command @command end |
Instance Method Details
#handler ⇒ Object
48 49 50 51 |
# File 'lib/cardio/commands.rb', line 48 def handler commands = self.class.commands @handler ||= commands.keys.find { |k| commands[k].include? command } end |
#rake_prefix ⇒ Object
78 79 80 |
# File 'lib/cardio/commands.rb', line 78 def rake_prefix "card" end |
#rescue? ⇒ Boolean
44 45 46 |
# File 'lib/cardio/commands.rb', line 44 def rescue? args.delete "--rescue" end |
#run ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cardio/commands.rb', line 53 def run case handler when :rails run_rails when :rake run_rake when :custom send "run_#{command}" else unrecognized end exit 0 end |
#run_help ⇒ Object
~~~~~~~~~ CUSTOM COMMANDS ~~~~~~~~~~~~ #
84 85 86 |
# File 'lib/cardio/commands.rb', line 84 def run_help puts File.read(File.("../commands/USAGE", __FILE__)) end |
#run_jasmine ⇒ Object
109 110 111 112 |
# File 'lib/cardio/commands.rb', line 109 def run_jasmine require "cardio/commands/rake_command" RakeCommand.new("spec:javascript", envs: "test").run end |
#run_new ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cardio/commands.rb', line 88 def run_new if ["-h", "--help"].include? args.first require "cardio/commands/application" else puts "Can't initialize a new deck within the directory of another, " \ "please change to a non-deck directory first.\n" puts "Type 'decko' for help." exit 1 end end |
#run_rails ⇒ Object
runs all commands in “rails” list
68 69 70 |
# File 'lib/cardio/commands.rb', line 68 def run_rails require "rails/commands" end |
#run_rake ⇒ Object
runs all commands in “rake” list
73 74 75 76 |
# File 'lib/cardio/commands.rb', line 73 def run_rake require "cardio/commands/rake_command" RakeCommand.new("#{rake_prefix}:#{command}", args).run end |
#run_rspec ⇒ Object
104 105 106 107 |
# File 'lib/cardio/commands.rb', line 104 def run_rspec require "cardio/commands/rspec_command" RspecCommand.new(args).run end |
#run_version ⇒ Object
99 100 101 102 |
# File 'lib/cardio/commands.rb', line 99 def run_version require "card/version" puts "Decko #{Card::Version.release}" end |
#unrecognized ⇒ Object
~~~~~~~~~~~~~~~~~~~~~ catch-all ————– #
116 117 118 119 120 |
# File 'lib/cardio/commands.rb', line 116 def unrecognized puts "Error: Command not recognized: #{command}" run_help exit 1 end |