Class: EngineCart::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/engine_cart/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_gemfile_includeObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/engine_cart/install_generator.rb', line 48

def add_gemfile_include
  append_file "Gemfile" do
    <<-EOF

  # the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app
  file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
  if File.exist?(file)
puts "Loading \#{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(file)
  else
# we get here when we haven't yet generated the testing app via engine_cart
gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']

if ENV['RAILS_VERSION'] && ENV['RAILS_VERSION'] =~ /^4.2/
  gem 'responders', "~> 2.0"
  gem 'sass-rails', ">= 5.0"
else
  gem 'sass-rails', "< 5.0"
end
  end
    EOF
  end
end

#create_test_app_templatesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/engine_cart/install_generator.rb', line 8

def create_test_app_templates
  empty_directory EngineCart.templates_path

  empty_directory File.expand_path("lib/generators", EngineCart.templates_path)

  create_file File.expand_path("lib/generators/test_app_generator.rb", EngineCart.templates_path), :skip => true do
    <<-EOF
    require 'rails/generators'

    class TestAppGenerator < Rails::Generators::Base
      source_root "#{EngineCart.templates_path}"

      # if you need to generate any additional configuration
      # into the test app, this generator will be run immediately
      # after setting up the application

      def install_engine
        generate '#{EngineCart.current_engine_name}:install'
      end
    end

    EOF
  end
end

#ignore_test_appObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/engine_cart/install_generator.rb', line 33

def ignore_test_app
  # Ignore the generated test app in the gem's .gitignore file
  git_root = (`git rev-parse --show-toplevel` rescue '.').strip

  # If we don't have a .gitignore file already, don't worry about it
  return unless File.exist? File.expand_path('.gitignore', git_root)

  # If the directory is already ignored (somehow) don't worry about it
  return if (system('git', 'check-ignore', TEST_APP, '-q') rescue false)

  append_file  File.expand_path('.gitignore', git_root) do
    "\n#{EngineCart.destination}\n"
  end
end