Class: Cardio::Commands

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Accessors

aliases, commands

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

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'lib/cardio/commands.rb', line 6

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/cardio/commands.rb', line 6

def command
  @command
end

Instance Method Details

#handlerObject



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_prefixObject



78
79
80
# File 'lib/cardio/commands.rb', line 78

def rake_prefix
  "card"
end

#rescue?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/cardio/commands.rb', line 44

def rescue?
  args.delete "--rescue"
end

#runObject



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_helpObject

~~~~~~~~~ CUSTOM COMMANDS ~~~~~~~~~~~~ #



84
85
86
# File 'lib/cardio/commands.rb', line 84

def run_help
  puts File.read(File.expand_path("../commands/USAGE", __FILE__))
end

#run_jasmineObject



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_newObject



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_railsObject

runs all commands in “rails” list



68
69
70
# File 'lib/cardio/commands.rb', line 68

def run_rails
  require "rails/commands"
end

#run_rakeObject

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_rspecObject



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_versionObject



99
100
101
102
# File 'lib/cardio/commands.rb', line 99

def run_version
  require "card/version"
  puts "Decko #{Card::Version.release}"
end

#unrecognizedObject

~~~~~~~~~~~~~~~~~~~~~ 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