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.6.0'
Class Method Summary
collapse
Class Method Details
.check_for_gemfile_stanza ⇒ Object
121
122
123
124
125
126
127
128
|
# File 'lib/engine_cart.rb', line 121
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
109
110
111
|
# File 'lib/engine_cart.rb', line 109
def self.configuration(options = {})
@configuration ||= EngineCart::Configuration.new(options)
end
|
.debug=(debug) ⇒ Object
130
131
132
|
# File 'lib/engine_cart.rb', line 130
def self.debug=(debug)
@debug = debug
end
|
.debug? ⇒ Boolean
134
135
136
|
# File 'lib/engine_cart.rb', line 134
def self.debug?
@debug
end
|
.env_fingerprint ⇒ Object
105
106
107
|
# File 'lib/engine_cart.rb', line 105
def self.env_fingerprint
{ RUBY_DESCRIPTION: RUBY_DESCRIPTION, BUNDLE_GEMFILE: Bundler.default_gemfile.to_s }.reject { |k, v| v.nil? || v.empty? }
end
|
101
102
103
|
# File 'lib/engine_cart.rb', line 101
def self.
@extra_fingerprinted_files || []
end
|
97
98
99
|
# File 'lib/engine_cart.rb', line 97
def self.()
@extra_fingerprinted_files =
end
|
.fingerprint ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/engine_cart.rb', line 80
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
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
|
# File 'lib/engine_cart.rb', line 39
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
35
36
37
|
# File 'lib/engine_cart.rb', line 35
def self.fingerprint_expired?
!fingerprint_current?
end
|
.fingerprinted_files ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/engine_cart.rb', line 88
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
76
77
78
|
# File 'lib/engine_cart.rb', line 76
def self.stored_fingerprint_file
File.expand_path('.generated_engine_cart', EngineCart.destination)
end
|
.with_unbundled_env ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/engine_cart.rb', line 15
def self.with_unbundled_env
method = if Bundler.respond_to?(:with_unbundled_env)
:with_unbundled_env
else
:with_clean_env
end
Bundler.public_send(method) do
yield
end
end
|
.within_test_app ⇒ Object
.write_fingerprint ⇒ Object
70
71
72
73
74
|
# File 'lib/engine_cart.rb', line 70
def self.write_fingerprint
File.open(stored_fingerprint_file, 'w') do |f|
f.write(EngineCart.fingerprint.to_json)
end
end
|