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 =
'2.4.0'
Class Method Summary
collapse
Class Method Details
.check_for_gemfile_stanza ⇒ Object
109
110
111
112
113
114
115
116
|
# File 'lib/engine_cart.rb', line 109
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
97
98
99
|
# File 'lib/engine_cart.rb', line 97
def self.configuration(options = {})
@configuration ||= EngineCart::Configuration.new(options)
end
|
.debug=(debug) ⇒ Object
118
119
120
|
# File 'lib/engine_cart.rb', line 118
def self.debug=(debug)
@debug = debug
end
|
.debug? ⇒ Boolean
122
123
124
|
# File 'lib/engine_cart.rb', line 122
def self.debug?
@debug
end
|
.env_fingerprint ⇒ Object
93
94
95
|
# File 'lib/engine_cart.rb', line 93
def self.env_fingerprint
{ RUBY_DESCRIPTION: RUBY_DESCRIPTION, BUNDLE_GEMFILE: Bundler.default_gemfile.to_s }.reject { |k, v| v.nil? || v.empty? }
end
|
89
90
91
|
# File 'lib/engine_cart.rb', line 89
def self.
@extra_fingerprinted_files || []
end
|
85
86
87
|
# File 'lib/engine_cart.rb', line 85
def self.()
@extra_fingerprinted_files =
end
|
.fingerprint ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/engine_cart.rb', line 68
def self.fingerprint
{ env: env_fingerprint }.merge(files:
fingerprinted_files.map do |file|
{ file: file, fingerprint: Digest::MD5.file(file).to_s }
end
)
end
|
.fingerprint_current? ⇒ Boolean
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
|
# File 'lib/engine_cart.rb', line 27
def self.fingerprint_current?
unless File.exist? stored_fingerprint_file
STDERR.puts "No finger print file found: #{stored_fingerprint_file}" if debug?
return false
end
content = File.read(stored_fingerprint_file)
data = JSON.parse(content, symbolize_names: true)
calculated = fingerprint
return true if data == calculated
if debug?
STDERR.puts "Fingerprint mismatch:\n\n"
data.keys.each do |key|
case data[key]
when Array
data[key].zip(calculated[key]).each do |(stored, calc)|
STDERR.puts("#{key}:\nstored: #{stored}\ncalculate: #{calc}") if stored != calc
end
else
STDERR.puts("#{key}:\nstored: #{data[key]}\ncalculate: #{calculated[key]}") if data[key] != calculated[key]
end
end
end
false
rescue
false
end
|
.fingerprint_expired? ⇒ Boolean
23
24
25
|
# File 'lib/engine_cart.rb', line 23
def self.fingerprint_expired?
!fingerprint_current?
end
|
.fingerprinted_files ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/engine_cart.rb', line 76
def self.fingerprinted_files
Dir.glob("./*.gemspec").select { |f| File.file? f } +
[Bundler.default_gemfile.to_s] +
Dir.glob("./db/migrate/*").select { |f| File.file? f } +
Dir.glob("./lib/generators/**/**").select { |f| File.file? f } +
Dir.glob("./spec/test_app_templates/**/**").select { |f| File.file? f } +
configuration.
end
|
.gemfile_stanza_check_line ⇒ Object
2
3
4
|
# File 'lib/engine_cart/gemfile_stanza.rb', line 2
def self.gemfile_stanza_check_line
'engine_cart stanza: 2.5.0'
end
|
.gemfile_stanza_text ⇒ Object
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
44
|
# 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
case ENV['RAILS_VERSION']
when /^6.0/
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 4.0'
when /^5.[12]/
gem 'sass-rails', '~> 5.0'
gem 'sprockets', '~> 3.7'
gem 'thor', '~> 0.20'
end
end
end
# END ENGINE_CART BLOCK
EOF
end
|
.load_application!(path = nil) ⇒ Object
11
12
13
|
# File 'lib/engine_cart.rb', line 11
def self.load_application! path = nil
require File.expand_path("config/environment", path || EngineCart.destination)
end
|
.stored_fingerprint_file ⇒ Object
64
65
66
|
# File 'lib/engine_cart.rb', line 64
def self.stored_fingerprint_file
File.expand_path('.generated_engine_cart', EngineCart.destination)
end
|
.within_test_app ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/engine_cart.rb', line 15
def self.within_test_app
Dir.chdir(EngineCart.destination) do
Bundler.with_clean_env do
yield
end
end
end
|
.write_fingerprint ⇒ Object
58
59
60
61
62
|
# File 'lib/engine_cart.rb', line 58
def self.write_fingerprint
File.open(stored_fingerprint_file, 'w') do |f|
f.write(EngineCart.fingerprint.to_json)
end
end
|