Module: EngineCart

Defined in:
lib/generators/engine_cart/install_generator.rb,
lib/engine_cart.rb,
lib/engine_cart/engine.rb,
lib/engine_cart/version.rb,
lib/engine_cart/rake_task.rb,
lib/engine_cart/configuration.rb,
lib/engine_cart/gemfile_stanza.rb

Overview

EngineCartGenerator sets up an engine to use engine_cart-generated test apps

Defined Under Namespace

Modules: RakeTask Classes: Configuration, Engine, InstallGenerator

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Class Method Details

.check_for_gemfile_stanzaObject



59
60
61
62
63
64
65
66
# File 'lib/engine_cart.rb', line 59

def self.check_for_gemfile_stanza
  return unless File.exist? 'Gemfile'

  unless File.readlines('Gemfile').grep(/#{EngineCart.gemfile_stanza_check_line}/).any?
    Bundler.ui.warn "[EngineCart] For better results, consider updating the EngineCart stanza in your Gemfile with:\n\n"
    Bundler.ui.warn EngineCart.gemfile_stanza_text
  end
end

.configuration(options = {}) ⇒ Object



47
48
49
# File 'lib/engine_cart.rb', line 47

def self.configuration(options = {})
  @configuration ||= EngineCart::Configuration.new(options)
end

.default_fingerprintObject



39
40
41
# File 'lib/engine_cart.rb', line 39

def self.default_fingerprint
  EngineCart.env_fingerprint + (Dir.glob("./*.gemspec") + [Bundler.default_gemfile.to_s, Bundler.default_lockfile.to_s]).map {|f| File.mtime(f) }.max.to_s
end

.env_fingerprintObject



43
44
45
# File 'lib/engine_cart.rb', line 43

def self.env_fingerprint
  { 'RUBY_DESCRIPTION' => RUBY_DESCRIPTION, 'BUNDLE_GEMFILE' => Bundler.default_gemfile.to_s }.reject { |k, v| v.nil? || v.empty? }.to_s
end

.fingerprintObject



21
22
23
# File 'lib/engine_cart.rb', line 21

def self.fingerprint
  @fingerprint || (@fingerprint_proc || method(:default_fingerprint)).call
end

.fingerprint=(fingerprint) ⇒ Object



25
26
27
# File 'lib/engine_cart.rb', line 25

def self.fingerprint= fingerprint
  @fingerprint = fingerprint
end

.fingerprint_proc=(fingerprint_proc) ⇒ Object



29
30
31
# File 'lib/engine_cart.rb', line 29

def self.fingerprint_proc= fingerprint_proc
  @fingerprint_proc = fingerprint_proc
end

.gemfile_stanza_check_lineObject



2
3
4
# File 'lib/engine_cart/gemfile_stanza.rb', line 2

def self.gemfile_stanza_check_line
  "engine_cart stanza: 0.10.0"
end

.gemfile_stanza_textObject



6
7
8
9
10
11
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
# File 'lib/engine_cart/gemfile_stanza.rb', line 6

def self.gemfile_stanza_text
  <<-EOF.gsub(/^    /, '')
  # BEGIN ENGINE_CART BLOCK
  # engine_cart: #{EngineCart::VERSION}
  # #{EngineCart.gemfile_stanza_check_line}
  # 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('#{EngineCart.destination}', File.dirname(__FILE__)))
  if File.exist?(file)
    begin
      eval_gemfile file
    rescue Bundler::GemfileError => e
      Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
      Bundler.ui.warn e.message
    end
  else
    Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in \#{file}, using placeholder dependencies"

    if ENV['RAILS_VERSION']
      if ENV['RAILS_VERSION'] == 'edge'
        gem 'rails', github: 'rails/rails'
        ENV['ENGINE_CART_RAILS_OPTIONS'] = '--edge --skip-turbolinks'
      else
        gem 'rails', ENV['RAILS_VERSION']
      end
    end

    case ENV['RAILS_VERSION']
    when /^4\.2/
      gem 'responders', '~> 2.0'
      gem 'sass-rails', '>= 5.0'
      gem 'coffee-rails', '~> 4.1.0'
    when /^4\.[01]/
      gem 'sass-rails', '< 5.0'
    end
  end
  # END ENGINE_CART BLOCK
  EOF
end

.load_application!(path = nil) ⇒ Object



9
10
11
# File 'lib/engine_cart.rb', line 9

def self.load_application! path = nil
  require File.expand_path("config/environment", path || EngineCart.destination)
end

.rails_fingerprint_proc(extra_files = []) ⇒ Object



33
34
35
36
37
# File 'lib/engine_cart.rb', line 33

def self.rails_fingerprint_proc extra_files = []
  lambda do
    EngineCart.default_fingerprint + (Dir.glob("./db/migrate/*") + Dir.glob("./lib/generators/**/**") + Dir.glob("./spec/test_app_templates/**/**") + extra_files).map {|f| File.mtime(f) }.max.to_s
  end
end

.within_test_appObject



13
14
15
16
17
18
19
# File 'lib/engine_cart.rb', line 13

def self.within_test_app
  Dir.chdir(EngineCart.destination) do
    Bundler.with_clean_env do
      yield
    end
  end
end