Class: HappySeed::Generators::BaseGenerator

Inherits:
HappySeedGenerator show all
Defined in:
lib/generators/happy_seed/base/base_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fingerprintObject



8
9
10
# File 'lib/generators/happy_seed/base/base_generator.rb', line 8

def self.fingerprint
  File.exists?( "docs/README.00.base.rdoc" )
end

Instance Method Details

#install_seed_baseObject



12
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
118
119
120
121
122
123
124
125
126
127
# File 'lib/generators/happy_seed/base/base_generator.rb', line 12

def install_seed_base
  return if already_installed

  puts "Installing happy_seed:base environment"

  # We only want SQLITE in development not everywhere
  gsub_file 'Gemfile', /.*sqlite3.*/, ""

  gem 'puma'
  gem 'rails_12factor'
  gem 'haml-rails'

  gem_group :development, :test do
    gem 'sqlite3'
    gem 'rspec', '~> 3.5.0'
    gem 'rspec-rails', '~> 3.5.0'
    gem 'factory_girl_rails'
    gem 'capybara'
    gem 'cucumber-rails', branch: 'rails-5', require: false
    gem 'guard-rspec', '~> 4.6.4', require: false
    gem 'guard-cucumber'
    gem 'database_cleaner'
    gem 'spring-commands-rspec'
    gem 'spring-commands-cucumber'
    gem 'launchy'
    gem 'vcr'
    gem 'faker'
    gem 'dotenv-rails'
    gem 'rdiscount'
    gem 'rails-controller-testing'
    gem 'better_errors'
    gem 'binding_of_caller'
  end

  gem_group :test do
    gem 'webmock'
    gem 'fakeredis', require: 'fakeredis/rspec'
  end

  gem_group :production do
    gem 'pg'
    gem 'lograge'
  end

  Bundler.with_clean_env do
    run "bundle install --without production"
  end

  gsub_file "app/assets/javascripts/application.js", /= require turbolinks/, "require turbolinks"

  # Install rspec
  generate "rspec:install"
  gsub_file ".rspec", "--warnings\n", ""
  append_to_file ".rspec", "--format documentation\n"

  # Install cucumber
  generate "cucumber:install"

  append_to_file "features/support/env.rb", "\nWorld(FactoryGirl::Syntax::Methods)\n"

  # Install Guard
  run "guard init"

  # Use the spring version and also run everything on startup
  gsub_file "Guardfile", 'cmd: "bundle exec rspec"', 'cmd: "bin/rspec", all_on_start: true'
  # gsub_file "Guardfile", 'guard "cucumber"', 'guard "cucumber", cli: "--color --strict"'

  directory '.'
  append_to_file '.gitignore', ".env\n"

  remove_file "application_controller.rb"
  remove_file "test"

  inject_into_file 'app/controllers/application_controller.rb', 
    File.read( find_in_source_paths('application_controller.rb') ), 
    after: /protect_from_forgery.*\n/

  inject_into_class 'config/application.rb', 
    :Application, 
    "    config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components')"

  inject_into_file 'config/environments/test.rb', 
    "  config.log_level = :error\n", 
    before: "end\n"

  inject_into_file 'config/environments/development.rb', 
    "  config.assets.quiet = true\n", 
    before: "end\n"

  inject_into_file 'config/environments/production.rb', 
    "  config.lograge.enabled = true\n  config.assets.quiet = true\n", 
    before: "end\n"

  begin
    inject_into_file 'spec/rails_helper.rb', "require 'webmock/rspec'\n", after: "'rspec/rails'\n"
  rescue
    say_status :spec, "Unable to add webmock to rails_helper.rb", :red
  end

  begin
    inject_into_file 'spec/rails_helper.rb', "\n  config.include FactoryGirl::Syntax::Methods\n", :before => "\nend\n"
    inject_into_file 'spec/rails_helper.rb', "\n  [:controller, :view, :request].each do |type|\n    config.include ::Rails::Controller::Testing::TestProcess, :type => type\n    config.include ::Rails::Controller::Testing::TemplateAssertions, :type => type\n    config.include ::Rails::Controller::Testing::Integration, :type => type\n  end", :before => "\nend\n"
    append_to_file 'spec/rails_helper.rb', "\nVCR.configure do |c|\n  c.cassette_library_dir  = Rails.root.join('spec', 'vcr')\n  c.hook_into :webmock\nend\n"
  rescue
    say_status :spec, "Unable to add factory girl and VCR to rails_helper.rb", :red
  end

  begin
    inject_into_file 'Rakefile', "module TempFixForRakeLastComment\n  def last_comment\n    last_description\n  end\nend\nRake::Application.send :include, TempFixForRakeLastComment\n", before: "Rails.application.load_tasks"
  rescue 
    say_status :spec, "Unable to add Rake workaround for last_comment"
  end

  route "get '/setup' => 'setup#index'"
  route "root 'setup#index'"
end