Class: BnrCommand

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/bnr_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



126
127
128
# File 'lib/bnr_command.rb', line 126

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#destroy(name) ⇒ Object



121
122
123
124
# File 'lib/bnr_command.rb', line 121

def destroy(name)
  run "heroku apps:destroy #{heroku_name(name)} --confirm #{heroku_name(name)}"
  remove_dir name
end

#new(name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/bnr_command.rb', line 13

def new(name)
  @name = name
  run "rails new #{name} --skip-bundle -T -q -d #{options[:database]}"
  if options[:ruby] == 'rvm'
    copy_file 'templates/ruby-version', "#{name}/.ruby-version"
  end
  inside name do
    run "git init -q"
    gsub_file "Gemfile", /^ *#.*$/, ''
      gsub_file "Gemfile", /^ *$\n/, ''
    append_to_file "Gemfile" do
      <<-EOF
ruby '2.0.0'

gem 'bootstrap-sass', '~> 2.0.4.0'
gem 'foreman'
gem 'unicorn'
gem 'slim-rails'
group :test, :development do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'forgery'
gem 'heroku'
gem 'zonebie'
end
group :test do
gem 'capybara'
gem 'launchy'
gem 'database_cleaner'
gem 'capybara-webkit'
gem 'simplecov'
end
      EOF
    end
    run "gem install bundler"
    run "bundle install --quiet"
    run "bundle exec rails g rspec:install"
    run "bundle exec rails g forgery"
    insert_into_file 'spec/spec_helper.rb', "\nrequire 'capybara/rspec'", after: "require 'rspec/autorun'"
    gsub_file 'spec/spec_helper.rb', / *# Remove this[^\n]*\n *config\.fixture_path[^\n]*\n\n/m, ''
      gsub_file 'spec/spec_helper.rb', /config.use_transactional_fixtures = true/, 'config.use_transactional_fixtures = false'
    insert_into_file 'spec/spec_helper.rb', after: "config.infer_base_class_for_anonymous_controllers = false\n" do
      <<-EOF

config.before(:suite) do
  DatabaseCleaner.strategy = :truncation
end

config.before(:each) do
  DatabaseCleaner.start
end

config.after(:each) do
  DatabaseCleaner.clean
end

config.order = "random"
      EOF
    end
    append_to_file 'spec/spec_helper.rb', "\nCapybara.javascript_driver = :webkit\n"
    prepend_to_file 'spec/spec_helper.rb' do
      <<-EOF
require 'simplecov'
SimpleCov.start
Zonebie.set_random_timezone
      EOF
    end
    append_to_file '.gitignore', "\ncoverage\n.rvmrc"
    remove_file 'public/index.html'
    remove_file 'README.rdoc'
    remove_file 'doc/README_FOR_APP'
    gsub_file 'config/database.yml', /username: .*$/, 'username:'
    run 'bundle exec rake db:create'

  end

  # Layout file
  remove_file "#{name}/app/views/layouts/application.html.erb"
  copy_file   "templates/layout.html.slim", "#{name}/app/views/layouts/application.html.slim"

  # Remove css and js application files
  remove_file "#{name}/app/assets/javascripts/application.js"
  remove_file "#{name}/app/assets/stylesheets/application.css"
  copy_file   "templates/application.js.coffee", "#{name}/app/assets/javascripts/application.js.coffee"
  copy_file   "templates/application.css.scss",  "#{name}/app/assets/stylesheets/application.css.scss"

  copy_file "templates/README.md", "#{name}/README.md"
  copy_file "templates/home_controller.rb", "#{name}/app/controllers/home_controller.rb"
  copy_file "templates/index.slim", "#{name}/app/views/home/index.slim"
  remove_file "#{name}/config/routes.rb"
  template "templates/routes.rb.erb", "#{name}/config/routes.rb"

  template "templates/Procfile", "#{name}/Procfile"
  template "templates/unicorn.rb", "#{name}/config/unicorn.rb"

  inside name do
    run 'bundle exec rake db:migrate'
    run 'git add .'
    run 'git commit -m "Initial Commit"'
    if options[:host] == 'heroku'
      run "heroku apps:create #{heroku_name(name)} -s cedar"
      run 'git push heroku master'
    end
  end
end