Class: Appraisal::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/appraisal/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/appraisal/cli.rb', line 108

def method_missing(name, *args, &block)
  matching_appraisal = AppraisalFile.new.appraisals.detect do |appraisal|
    appraisal.name == name.to_s
  end

  if matching_appraisal
    Command.new(args, gemfile: matching_appraisal.gemfile_path).run
  else
    AppraisalFile.each do |appraisal|
      Command.new(ARGV, gemfile: appraisal.gemfile_path).run
    end
  end
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/appraisal/cli.rb', line 38

def exit_on_failure?
  true
end

.help(shell, subcommand = false) ⇒ Object

Override help command to print out usage



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/appraisal/cli.rb', line 13

def help(shell, subcommand = false)
  shell.say strip_heredoc(<<-HELP)
    Appraisal: Find out what your Ruby gems are worth.

    Usage:
      appraisal [APPRAISAL_NAME] EXTERNAL_COMMAND

      If APPRAISAL_NAME is given, only run that EXTERNAL_COMMAND against the given
      appraisal, otherwise it runs the EXTERNAL_COMMAND against all appraisals.
  HELP

  if File.exist?("Appraisals")
    shell.say
    shell.say "Available Appraisal(s):"

    AppraisalFile.each do |appraisal|
      shell.say "  - #{appraisal.name}"
    end
  end

  shell.say

  super
end

Instance Method Details

#cleanObject



83
84
85
# File 'lib/appraisal/cli.rb', line 83

def clean
  FileUtils.rm_f Dir["gemfiles/*.{gemfile,gemfile.lock}"]
end

#generateObject



76
77
78
79
80
# File 'lib/appraisal/cli.rb', line 76

def generate
  AppraisalFile.each do |appraisal|
    appraisal.write_gemfile
  end
end

#installObject



66
67
68
69
70
71
72
73
# File 'lib/appraisal/cli.rb', line 66

def install
  invoke :generate, [], {}

  AppraisalFile.each do |appraisal|
    appraisal.install(options)
    appraisal.relativize
  end
end

#listObject



97
98
99
# File 'lib/appraisal/cli.rb', line 97

def list
  AppraisalFile.new.appraisals.each { |appraisal| puts appraisal.name }
end

#update(*gems) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/appraisal/cli.rb', line 88

def update(*gems)
  invoke :generate, []

  AppraisalFile.each do |appraisal|
    appraisal.update(gems)
  end
end

#versionObject



102
103
104
# File 'lib/appraisal/cli.rb', line 102

def version
  puts "Appraisal #{VERSION}"
end