Class: GemSuit::CLI

Inherits:
Thor
  • Object
show all
Includes:
Application, Base, Builder, Config
Defined in:
lib/gem_suit/cli.rb,
lib/gem_suit/cli/base.rb,
lib/gem_suit/cli/config.rb,
lib/gem_suit/cli/builder.rb,
lib/gem_suit/cli/base/shell.rb,
lib/gem_suit/cli/base/utils.rb,
lib/gem_suit/cli/application.rb,
lib/gem_suit/cli/config/hash.rb,
lib/gem_suit/cli/builder/generator.rb,
lib/gem_suit/cli/builder/rails_app.rb,
lib/gem_suit/cli/application/io_buffer.rb

Defined Under Namespace

Modules: Application, Base, Builder, Config Classes: Error

Constant Summary

Constants included from Config

Config::FILENAME

Instance Method Summary collapse

Methods included from Application

included

Methods included from Builder

included

Methods included from Config

included

Methods included from Base

included

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)

Raises:



145
146
147
# File 'lib/gem_suit/cli.rb', line 145

def method_missing(method, *args)
  raise Error, "Unrecognized command \"#{method}\". Please consult `suit help`."
end

Instance Method Details

#bundleObject

Raises:



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/gem_suit/cli.rb', line 130

def bundle
  raise Error, "Current directory path does not match either a GemSuit directory or a Rails dummy app. Quitting." unless suit_dir? || rails_dir?

  dirs = [File.expand_path("")]
  dirs.concat Dir["suit/rails-*/dummy"] if suit_dir?
  dirs.each do |dir|
    if [`cd #{dir} && bundle check`].flatten.any?{|line| line.include? "`bundle install`"}
      puts "Running `bundle install` (this can take several minutes...)".yellow
      system "cd #{dir} && bundle install"
    end
  end
end

#config(env = nil) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/gem_suit/cli.rb', line 72

def config(env = nil)
  global_options = [:rails_versions]
  case env
  when "global"
    if options.empty?
      log suit_config_global.to_str, true
    else
      options.reject{|k, v| !global_options.include? k.to_sym}.each do |key, value|
        suit_config_global[key] = value
      end
    end
  when nil
    assert_suit_dir
    if options.empty?
      log suit_config.to_str, true
    else
      options.reject{|k, v| global_options.include? k.to_sym}.each do |key, value|
        suit_config[key] = value
      end
    end
  else
    raise Error, "Invalid config enviroment #{env.inspect}"
  end
end

#console(environment = "development") ⇒ Object



107
108
109
# File 'lib/gem_suit/cli.rb', line 107

def console(environment = "development")
  rails :console, environment
end

#fitObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/gem_suit/cli.rb', line 59

def fit
  assert_suit_dir
  restore
  bundle_install
  bundle_install_apps
  rake_install if options.rake_install?
  ask_mysql_password
  create_mysql_test_database
  create_development_databases
end

#restoreObject



125
126
127
# File 'lib/gem_suit/cli.rb', line 125

def restore
  files :restore
end

#server(environment = "development") ⇒ Object



100
101
102
# File 'lib/gem_suit/cli.rb', line 100

def server(environment = "development")
  rails :server, environment
end

#tailor(name) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/gem_suit/cli.rb', line 23

def tailor(name)
  execute "bundle gem #{name}"

  opts = options.collect do |key, value|
    ["-", ("-no" unless value), "-#{key}"].compact.join "" if [:interactive, :extras, :mysql, :capybara, :verbose].include?(key.to_sym)
  end.compact.join " "

  system "cd #{name} && suit up #{opts}"
end

#test(section = "suit", file_or_pattern = nil) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/gem_suit/cli.rb', line 113

def test(section = "suit", file_or_pattern = nil)
  if Application::InstanceMethods.instance_methods.collect(&:to_s).include?(method = "test_#{section}")
    send method, file_or_pattern
  elsif file_or_pattern.nil?
    test_suit section
  else
    raise Error, "Unrecognized test section '#{section}'. Either leave it empty or pass 'suit', 'unit', 'functional' or 'integration'"
  end
end

#upObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gem_suit/cli.rb', line 35

def up
  assert_gem_dir true
  create_shared_assets
  configure_suit
  create_rails_apps
  generate_files

  opts = options.collect do |key, value|
    ["-", ("-no" unless value), "-#{key}"].compact.join "" if [:verbose].include?(key.to_sym)
  end.compact.join " "

  system "suit fit #{opts} --no-rake_install"
  puts "Barney Stinson says: 'Cheers! Your gem just got a little more legend!'".green
end