Module: EngineCart
- Defined in:
- lib/generators/engine_cart/install_generator.rb,
lib/engine_cart.rb,
lib/engine_cart/engine.rb,
lib/engine_cart/params.rb,
lib/engine_cart/version.rb,
lib/engine_cart/rake_task.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: Engine, InstallGenerator
Constant Summary
collapse
- VERSION =
'0.8.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.destination ⇒ Object
Destination to generate the test app into
10
11
12
|
# File 'lib/engine_cart/params.rb', line 10
def destination
@destination
end
|
.engine_name ⇒ Object
Name of the engine we’re testing
6
7
8
|
# File 'lib/engine_cart/params.rb', line 6
def engine_name
@engine_name
end
|
.rails_options ⇒ Object
Additional options when generating a test rails application
24
25
26
|
# File 'lib/engine_cart/params.rb', line 24
def rails_options
@rails_options
end
|
.template ⇒ Object
Path to a Rails application template
14
15
16
|
# File 'lib/engine_cart/params.rb', line 14
def template
@template
end
|
.templates_path ⇒ Object
Path to test app templates to make available to the test app generator
19
20
21
|
# File 'lib/engine_cart/params.rb', line 19
def templates_path
@templates_path
end
|
Class Method Details
.check_for_gemfile_stanza ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/engine_cart.rb', line 51
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
|
.current_engine_name ⇒ Object
9
10
11
|
# File 'lib/engine_cart.rb', line 9
def self.current_engine_name
engine_name || File.basename(Dir.glob("*.gemspec").first, '.gemspec')
end
|
.default_destination ⇒ Object
30
31
32
|
# File 'lib/engine_cart/params.rb', line 30
def self.default_destination
('.internal_test_app' if File.exist? '.internal_test_app') || ('spec/internal' if File.exist? 'spec/internal') || '.internal_test_app'
end
|
.default_fingerprint ⇒ Object
43
44
45
|
# File 'lib/engine_cart.rb', line 43
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_fingerprint ⇒ Object
47
48
49
|
# File 'lib/engine_cart.rb', line 47
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
|
.fingerprint ⇒ Object
25
26
27
|
# File 'lib/engine_cart.rb', line 25
def self.fingerprint
@fingerprint || (@fingerprint_proc || method(:default_fingerprint)).call
end
|
.fingerprint=(fingerprint) ⇒ Object
29
30
31
|
# File 'lib/engine_cart.rb', line 29
def self.fingerprint= fingerprint
@fingerprint = fingerprint
end
|
.fingerprint_proc=(fingerprint_proc) ⇒ Object
33
34
35
|
# File 'lib/engine_cart.rb', line 33
def self.fingerprint_proc= fingerprint_proc
@fingerprint_proc = fingerprint_proc
end
|
.gemfile_stanza_check_line ⇒ Object
4
5
6
|
# File 'lib/engine_cart/gemfile_stanza.rb', line 4
def self.gemfile_stanza_check_line
"engine_cart stanza: 0.8.0"
end
|
.gemfile_stanza_text ⇒ Object
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
|
# File 'lib/engine_cart/gemfile_stanza.rb', line 8
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"
gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^4.2/
gem 'responders', "~> 2.0"
gem 'sass-rails', ">= 5.0"
else
gem 'sass-rails', "< 5.0"
end
end
# END ENGINE_CART BLOCK
EOF
end
|
.load_application!(path = nil) ⇒ Object
13
14
15
|
# File 'lib/engine_cart.rb', line 13
def self.load_application! path = nil
require File.expand_path("config/environment", path || EngineCart.destination)
end
|
.rails_fingerprint_proc(extra_files = []) ⇒ Object
37
38
39
40
41
|
# File 'lib/engine_cart.rb', line 37
def self.rails_fingerprint_proc = []
lambda do
EngineCart.default_fingerprint + (Dir.glob("./db/migrate/*") + Dir.glob("./lib/generators/**/**") + Dir.glob("./spec/test_app_templates/**/**") + ).map {|f| File.mtime(f) }.max.to_s
end
end
|
.within_test_app ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/engine_cart.rb', line 17
def self.within_test_app
Dir.chdir(EngineCart.destination) do
Bundler.with_clean_env do
yield
end
end
end
|