wagons 0.0.1 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +1 -1
- data/README.rdoc +135 -9
- data/Rakefile +13 -5
- data/lib/generators/wagon/templates/%singular_name%.gemspec.tt +0 -2
- data/lib/generators/wagon/templates/.gitignore +5 -0
- data/lib/generators/wagon/templates/Gemfile.tt +5 -9
- data/lib/generators/wagon/templates/app/assets/images/.empty_directory +0 -0
- data/lib/generators/wagon/templates/app/controllers/.empty_directory +0 -0
- data/lib/generators/wagon/templates/app/models/.empty_directory +0 -0
- data/lib/generators/wagon/templates/app/views/.empty_directory +0 -0
- data/lib/generators/wagon/templates/db/fixtures/development/.empty_directory +0 -0
- data/lib/generators/wagon/templates/db/migrate/.empty_directory +0 -0
- data/lib/generators/wagon/templates/lib/%singular_name%/wagon.rb.tt +7 -4
- data/lib/generators/wagon/templates/test/fixtures/.empty_directory +0 -0
- data/lib/generators/wagon/wagon_generator.rb +23 -4
- data/lib/tasks/wagons.rake +119 -20
- data/lib/wagons/extensions/application.rb +14 -0
- data/lib/wagons/extensions/require_optional.rb +9 -0
- data/lib/wagons/{test_case.rb → extensions/test_case.rb} +4 -1
- data/lib/wagons/installer.rb +313 -0
- data/lib/wagons/railtie.rb +1 -1
- data/lib/wagons/version.rb +1 -1
- data/lib/wagons/view_helper.rb +58 -0
- data/lib/wagons/wagon.rb +125 -109
- data/lib/wagons/wagon_tasks.rake +9 -7
- data/lib/wagons.rb +44 -7
- data/test/dummy/Gemfile +8 -2
- data/test/dummy/Gemfile.lock +51 -48
- data/test/dummy/app/assets/javascripts/application.js +0 -2
- data/test/dummy/app/controllers/people_controller.rb +6 -0
- data/test/dummy/app/views/people/index.html.erb +6 -0
- data/test/dummy/app/views/shared/_sidebar.html.erb +3 -0
- data/test/dummy/config/initializers/wagon_app_version.rb +7 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +1230 -1586
- data/test/dummy/log/test.log +6458 -1772
- data/test/dummy/test/unit/person_test.rb +6 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- data/test/dummy/vendor/wagons/superliner/Gemfile +1 -5
- data/test/dummy/vendor/wagons/superliner/Gemfile.lock +46 -48
- data/test/dummy/vendor/wagons/superliner/app/controllers/cities_controller.rb +6 -0
- data/test/dummy/vendor/wagons/superliner/app/views/cities/index.html.erb +7 -0
- data/test/dummy/vendor/wagons/superliner/app/views/people/_list_superliner.html.erb +3 -0
- data/test/dummy/vendor/wagons/superliner/app/views/shared/_sidebar_superliner.html.erb +1 -0
- data/test/dummy/vendor/wagons/superliner/config/routes.rb +1 -1
- data/test/dummy/vendor/wagons/superliner/db/migrate/{20120606125258_create_cities.rb → 20120606125058_create_cities.rb} +0 -0
- data/test/dummy/vendor/wagons/superliner/dummy_superliner.gemspec +0 -2
- data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner/wagon.rb +3 -1
- data/test/dummy/vendor/wagons/superliner/test/functionals/cities_controller_test.rb +12 -0
- data/test/dummy/vendor/wagons/superliner/test/functionals/people_controller_test.rb +14 -0
- data/test/dummy/vendor/wagons/superliner/test/unit/city_test.rb +4 -1
- data/test/dummy/vendor/wagons/superliner/test/wagon_test.rb +7 -5
- data/test/wagons_installer_test.rb +225 -0
- metadata +241 -169
- data/test/dummy/dummy.gemspec +0 -17
@@ -0,0 +1,313 @@
|
|
1
|
+
module Wagons
|
2
|
+
|
3
|
+
# Helper class to install wagons into the current application.
|
4
|
+
# Wagons are searched for in the system gem repository.
|
5
|
+
#
|
6
|
+
# If you want to use the #install method, add "gem 'open4'" to
|
7
|
+
# your Gemfile.
|
8
|
+
class Installer
|
9
|
+
|
10
|
+
attr_accessor :include_version_in_wagonfile
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@include_version_in_wagonfile = true
|
14
|
+
end
|
15
|
+
|
16
|
+
# Gem specifications of all installed wagons.
|
17
|
+
def installed
|
18
|
+
@installed ||= Wagons.all.collect(&:gemspec)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Most recent gem specifications of all wagons available in GEM_HOME.
|
22
|
+
def available
|
23
|
+
return @available if defined?(@available)
|
24
|
+
|
25
|
+
# only keep most recent version in @available
|
26
|
+
@available = []
|
27
|
+
load_available_specs.each do |spec|
|
28
|
+
if prev = @available.find {|w| w.name == spec.name }
|
29
|
+
if prev.version < spec.version
|
30
|
+
@available.delete(prev)
|
31
|
+
@available << spec
|
32
|
+
end
|
33
|
+
else
|
34
|
+
@available << spec
|
35
|
+
end
|
36
|
+
end
|
37
|
+
@available
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Most recent gem specifications of available, but not installed (in any version) wagons.
|
42
|
+
def not_installed
|
43
|
+
exclude_specs(available, installed)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Most recent gem specifications of available and installed (in an older version) wagons.
|
47
|
+
def updates
|
48
|
+
available.select do |spec|
|
49
|
+
if wagon = installed_spec(spec.name)
|
50
|
+
wagon.version < spec.version
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Install or update the wagons with the given names. I.e., adds the given
|
56
|
+
# wagon names to the Wagonfile and runs rake wagon:setup.
|
57
|
+
# After that, the application MUST be restarted to load the new wagons.
|
58
|
+
# Returns nil if everything is fine or a string with error messages.
|
59
|
+
# This method requires open4.
|
60
|
+
def install(names)
|
61
|
+
change_internal(names, :check_dependencies) do |specs|
|
62
|
+
content = File.read(wagonfile) rescue ""
|
63
|
+
wagonfile_update(specs)
|
64
|
+
|
65
|
+
begin
|
66
|
+
setup_wagons(specs)
|
67
|
+
rescue => e
|
68
|
+
wagonfile_write(content)
|
69
|
+
raise e
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Remove the wagons with the given names. I.e., reverts the migrations
|
75
|
+
# of the given wagon names if the wagon is not protected
|
76
|
+
# and removes the entries from the Wagonfile.
|
77
|
+
# Returns nil if everything is fine or a string with error messages.
|
78
|
+
def uninstall(names)
|
79
|
+
change_internal(names, :check_uninstalled_dependencies, :check_protected) do |specs|
|
80
|
+
remove_wagons(specs)
|
81
|
+
wagonfile_remove(specs)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get the gem specification of the installed wagon with the given name.
|
86
|
+
# Return nil if not found.
|
87
|
+
def installed_spec(name)
|
88
|
+
installed.find {|s| s.name == name }
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get the gem specification of an available wagon with the given name.
|
92
|
+
# Return nil if not found.
|
93
|
+
def available_spec(name)
|
94
|
+
available.find {|s| s.name == name}
|
95
|
+
end
|
96
|
+
|
97
|
+
# Update the Wagonfile with the given gem specifications.
|
98
|
+
def wagonfile_update(specs)
|
99
|
+
wagonfile_edit(specs) do |spec, content|
|
100
|
+
declaration = "gem '#{spec.name}'"
|
101
|
+
declaration += ", '#{spec.version.to_s}'" if include_version_in_wagonfile
|
102
|
+
unless content.sub!(gem_declaration_regexp(spec.name), declaration)
|
103
|
+
content += "\n#{declaration}"
|
104
|
+
end
|
105
|
+
content
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Remove the given gem specifications from the Wagonfile.
|
110
|
+
def wagonfile_remove(specs)
|
111
|
+
wagonfile_edit(specs) do |spec, content|
|
112
|
+
content.sub(gem_declaration_regexp(spec.name), '')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Check if all wagon dependencies of the given gem specifications
|
117
|
+
# are met by the installed wagons.
|
118
|
+
# Returns nil if everything is fine or a string with error messages.
|
119
|
+
def check_dependencies(specs)
|
120
|
+
missing = check_app_requirement(specs)
|
121
|
+
|
122
|
+
present = exclude_specs(installed, specs)
|
123
|
+
future = present + specs
|
124
|
+
|
125
|
+
check_all_dependencies(specs, future, missing)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Check if the app requirement of the given gem specifications
|
129
|
+
# are met by the current app version.
|
130
|
+
# Returns nil if everything is fine or a array with error messages.
|
131
|
+
def check_app_requirement(specs)
|
132
|
+
missing = []
|
133
|
+
specs.each do |spec|
|
134
|
+
if wagon = wagon_class(spec)
|
135
|
+
unless wagon.app_requirement.satisfied_by?(Wagons.app_version)
|
136
|
+
missing << "#{spec} requires application version #{wagon.app_requirement}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
missing
|
142
|
+
end
|
143
|
+
|
144
|
+
# Check if the wagon dependencies of the remaining wagons
|
145
|
+
# would still be met after the given gem specifications are uninstalled.
|
146
|
+
# Returns nil if everything is fine or a string with error messages.
|
147
|
+
def check_uninstalled_dependencies(specs)
|
148
|
+
present = exclude_specs(installed, specs)
|
149
|
+
check_all_dependencies(present, present)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Checks if the wagons for given gem specifications are protected.
|
153
|
+
# Returns nil if everything is fine or a string with error messages.
|
154
|
+
def check_protected(specs)
|
155
|
+
protected = []
|
156
|
+
specs.each do |spec|
|
157
|
+
msg = Wagons.find(spec.name).protect?
|
158
|
+
protected << msg if msg.is_a?(String)
|
159
|
+
end
|
160
|
+
protected.join("\n").presence
|
161
|
+
end
|
162
|
+
|
163
|
+
# List of available gem specifications with the given names.
|
164
|
+
# Raises an error if a name cannot be found.
|
165
|
+
def specs_from_names(names)
|
166
|
+
names.collect do |name|
|
167
|
+
spec = available_spec(name)
|
168
|
+
raise "#{name} was not found" if spec.nil?
|
169
|
+
spec
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Removes all gem specifications with the same name in to_be_excluded from full.
|
174
|
+
# Versions are ignored.
|
175
|
+
def exclude_specs(full, to_be_excluded)
|
176
|
+
full.clone.delete_if {|s| to_be_excluded.find {|d| s.name == d.name } }
|
177
|
+
end
|
178
|
+
|
179
|
+
# Wagonfile
|
180
|
+
def wagonfile
|
181
|
+
Rails.root.join("Wagonfile")
|
182
|
+
end
|
183
|
+
|
184
|
+
# The wagon class of the given spec.
|
185
|
+
def wagon_class(spec)
|
186
|
+
@wagon_classes ||= {}
|
187
|
+
return @wagon_classes[spec] if @wagon_classes.has_key?(spec)
|
188
|
+
|
189
|
+
clazz = nil
|
190
|
+
file = File.join(spec.gem_dir, 'lib', spec.name, 'wagon.rb')
|
191
|
+
if File.exists?(file)
|
192
|
+
require file
|
193
|
+
clazz = "#{spec.name.camelize}::Wagon".constantize
|
194
|
+
else
|
195
|
+
raise "#{spec.name} wagon class not found in #{file}"
|
196
|
+
end
|
197
|
+
@wagon_classes[spec] = clazz
|
198
|
+
end
|
199
|
+
|
200
|
+
private
|
201
|
+
|
202
|
+
def load_available_specs
|
203
|
+
paths = [ENV['GEM_HOME']]
|
204
|
+
paths += (ENV['GEM_PATH'] || "").split(File::PATH_SEPARATOR)
|
205
|
+
paths.collect(&:presence).compact.collect do |path|
|
206
|
+
Dir[File.join(path, 'specifications', "#{Wagons.app_name}_*.gemspec")].collect do |gemspec|
|
207
|
+
Gem::Specification.load(gemspec)
|
208
|
+
end
|
209
|
+
end.flatten
|
210
|
+
end
|
211
|
+
|
212
|
+
def perform_checks(specs, checks)
|
213
|
+
checks.each do |check|
|
214
|
+
if msg = send(check, specs)
|
215
|
+
return msg
|
216
|
+
end
|
217
|
+
end
|
218
|
+
nil
|
219
|
+
end
|
220
|
+
|
221
|
+
def check_all_dependencies(to_check, all, missing = [])
|
222
|
+
to_check.each do |spec|
|
223
|
+
spec.runtime_dependencies.each do |dep|
|
224
|
+
if dep.name.start_with?("#{Wagons.app_name}_") &&
|
225
|
+
all.none? {|s| dep.matches_spec?(s) }
|
226
|
+
missing << "#{spec.name} requires #{dep.name} #{dep.requirement}"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
missing.join("\n").presence
|
232
|
+
end
|
233
|
+
|
234
|
+
def gem_declaration_regexp(name)
|
235
|
+
/^.*gem\s+('|")#{name}('|").*$/
|
236
|
+
end
|
237
|
+
|
238
|
+
def wagonfile_edit(specs)
|
239
|
+
content = File.read(wagonfile) rescue ""
|
240
|
+
|
241
|
+
specs.each do |spec|
|
242
|
+
content = yield spec, content
|
243
|
+
end
|
244
|
+
content.gsub!(/(\n\s*\n\s*)+/, "\n") # remove empty lines
|
245
|
+
|
246
|
+
wagonfile_write(content.strip)
|
247
|
+
end
|
248
|
+
|
249
|
+
def wagonfile_write(content)
|
250
|
+
File.open(wagonfile, 'w') do |f|
|
251
|
+
f.puts content
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def setup_wagons(specs)
|
256
|
+
require 'open4'
|
257
|
+
|
258
|
+
env = Rails.env
|
259
|
+
cmd = setup_command(specs)
|
260
|
+
Rails.logger.info(cmd)
|
261
|
+
|
262
|
+
Bundler.with_clean_env do
|
263
|
+
ENV['RAILS_ENV'] = env
|
264
|
+
execute_setup(cmd)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def remove_wagons(specs)
|
269
|
+
Wagons.all.reverse.each do |wagon|
|
270
|
+
if specs.find {|spec| wagon.gem_name == spec.name }
|
271
|
+
wagon.unload_seed
|
272
|
+
wagon.revert
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
def setup_command(specs)
|
278
|
+
wagons = specs.collect {|s| s.name.sub(/^#{Wagons.app_name}_/, '') }.join(',')
|
279
|
+
"cd #{Rails.root} && bundle exec rake wagon:setup WAGON=#{wagons} -t"
|
280
|
+
end
|
281
|
+
|
282
|
+
def execute_setup(cmd)
|
283
|
+
msg = nil
|
284
|
+
status = Open4.popen4(cmd) do |pid, input, output, errors|
|
285
|
+
msg = errors.read
|
286
|
+
end
|
287
|
+
|
288
|
+
if status.exitstatus.to_i != 0
|
289
|
+
raise msg.presence || "Unknown error while running wagon:setup"
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def change_internal(names, *checks)
|
294
|
+
specs = specs_from_names(names)
|
295
|
+
|
296
|
+
if msg = perform_checks(specs, checks)
|
297
|
+
msg
|
298
|
+
else
|
299
|
+
yield specs
|
300
|
+
nil
|
301
|
+
end
|
302
|
+
rescue Exception => e
|
303
|
+
handle_exception(e, names)
|
304
|
+
end
|
305
|
+
|
306
|
+
def handle_exception(e, names)
|
307
|
+
msg = e.message
|
308
|
+
Rails.logger.error msg + "\n\t" + e.backtrace.join("\n\t")
|
309
|
+
msg
|
310
|
+
end
|
311
|
+
|
312
|
+
end
|
313
|
+
end
|
data/lib/wagons/railtie.rb
CHANGED
data/lib/wagons/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
module Wagons
|
2
|
+
module ViewHelper
|
3
|
+
|
4
|
+
# Renders all partials with names that match "_[ key ]_*.[ format ].[ handler ]"
|
5
|
+
# in alphabetical order.
|
6
|
+
# Accepts an additional option :folder to pass an additional folder to search
|
7
|
+
# extension partials in.
|
8
|
+
def render_extensions(key, options = {})
|
9
|
+
extensions = find_extension_partials(key, options.delete(:folder)).collect do |partial|
|
10
|
+
render options.merge(:partial => partial)
|
11
|
+
end
|
12
|
+
safe_join(extensions)
|
13
|
+
end
|
14
|
+
|
15
|
+
# The view folders relative to app/views in which extensions are searched for.
|
16
|
+
# Uses the folder of the current template.
|
17
|
+
def extension_folders
|
18
|
+
[current_template_folder]
|
19
|
+
end
|
20
|
+
|
21
|
+
# The folder of the current partial relative to app/views
|
22
|
+
def current_template_folder
|
23
|
+
@virtual_path[/(.+)\/.*/, 1]
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def find_extension_partials(key, folder = nil)
|
29
|
+
folders = extension_folders.dup
|
30
|
+
folders << folder if folder
|
31
|
+
|
32
|
+
files = find_extension_files(key, folders).sort_by { |f| File.basename(f) }
|
33
|
+
files_to_partial_names(files)
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_extension_files(key, folders)
|
37
|
+
view_paths.collect do |path|
|
38
|
+
folders.collect do |folder|
|
39
|
+
lookup_context.formats.collect do |format|
|
40
|
+
lookup_context.handlers.collect do |handler|
|
41
|
+
Dir.glob(File.join(path, folder, "_#{key}_*.#{format}.#{handler}"))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end.flatten
|
46
|
+
end
|
47
|
+
|
48
|
+
def files_to_partial_names(files)
|
49
|
+
files.collect do |f|
|
50
|
+
m = f.match(/views.(.+?[\/\\])_(.+)\.\w+\.\w+$/)
|
51
|
+
m[1] + m[2]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
ActionView::Base.send(:include, Wagons::ViewHelper) if defined?(ActionView::Base)
|
data/lib/wagons/wagon.rb
CHANGED
@@ -1,112 +1,128 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
gemspec
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Wagons
|
4
|
+
|
5
|
+
# A wagon is an extension to your application train running on Rails.
|
6
|
+
#
|
7
|
+
# Wagons are built on Rails Engines. To change an engine to a wagon,
|
8
|
+
# simply include this module into your own Engine.
|
9
|
+
module Wagon
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
# Version from the gemspec.
|
13
|
+
def version
|
14
|
+
gemspec.version
|
15
|
+
end
|
16
|
+
|
17
|
+
# Human readable name.
|
18
|
+
def label
|
19
|
+
gemspec.summary
|
20
|
+
end
|
21
|
+
|
22
|
+
# Simple system name, without application prefix.
|
23
|
+
def wagon_name
|
24
|
+
gem_name.sub(/^#{Wagons.app_name}_/, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
# Name of the gem.
|
28
|
+
def gem_name
|
29
|
+
class_name = self.class.name.demodulize.underscore
|
30
|
+
engine_name.sub(/_#{class_name}$/, '')
|
31
|
+
end
|
32
|
+
|
33
|
+
# Description from the gemspec.
|
34
|
+
def description
|
35
|
+
gemspec.description
|
36
|
+
end
|
37
|
+
|
38
|
+
# Direct dependencies on other wagons.
|
39
|
+
def dependencies
|
40
|
+
gemspec.dependencies.collect(&:name).
|
41
|
+
select {|dep| dep =~ /\A#{Wagons.app_name}_/ }.
|
42
|
+
collect { |dep| Wagons.find(dep) || raise("No wagon #{dep} found") }
|
43
|
+
end
|
44
|
+
|
45
|
+
# Recursive depdencies on other wagons.
|
46
|
+
def all_dependencies
|
47
|
+
dependencies.collect {|dep| dep.all_dependencies + [dep] }.flatten.uniq
|
48
|
+
end
|
49
|
+
|
50
|
+
# Gem Specification.
|
51
|
+
def gemspec
|
52
|
+
Gem::Specification.find_by_name(gem_name)
|
53
|
+
end
|
54
|
+
|
55
|
+
# If true, this wagon may not be removed. Override as required.
|
56
|
+
# May return a string with a message, why the wagon must not be removed.
|
57
|
+
def protect?
|
58
|
+
false
|
59
|
+
end
|
60
|
+
|
61
|
+
# Run the migrations.
|
62
|
+
def migrate(version = nil)
|
63
|
+
ActiveRecord::Migrator.migrate(migrations_paths, version)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Revert the migrations.
|
67
|
+
def revert
|
68
|
+
ActiveRecord::Migrator.migrate(migrations_paths, 0)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Load seed data in db/fixtures.
|
72
|
+
def load_seed
|
73
|
+
SeedFu.seed seed_fixtures
|
74
|
+
end
|
75
|
+
|
76
|
+
# Unload seed data in db/fixtures.
|
77
|
+
def unload_seed
|
78
|
+
SeedFuNdo.unseed seed_fixtures
|
79
|
+
end
|
80
|
+
|
81
|
+
# Hash of the seed models to their existing records.
|
82
|
+
def existing_seeds
|
83
|
+
silence_stream(STDOUT) do
|
84
|
+
SeedFuNdo.existing_seeds seed_fixtures
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# The version requirement for the main application.
|
89
|
+
def app_requirement
|
90
|
+
self.class.app_requirement
|
91
|
+
end
|
92
|
+
|
93
|
+
# Paths for migration files.
|
94
|
+
def migrations_paths
|
95
|
+
paths['db/migrate'].existent
|
96
|
+
end
|
97
|
+
|
98
|
+
# Loads tasks into the main Rails application.
|
99
|
+
# Overwritten to only load own rake tasks, without install:migrations task from Rails::Engine
|
100
|
+
def load_tasks(app=self)
|
101
|
+
railties.all { |r| r.load_tasks(app) }
|
102
|
+
extend Rake::DSL if defined? Rake::DSL
|
103
|
+
self.class.rake_tasks.each { |block| self.instance_exec(app, &block) }
|
104
|
+
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def seed_fixtures
|
110
|
+
fixtures = root.join('db', 'fixtures')
|
111
|
+
ENV['NO_ENV'] ? [fixtures] : [fixtures, File.join(fixtures, Rails.env)]
|
112
|
+
end
|
113
|
+
|
114
|
+
module ClassMethods
|
115
|
+
# Get or set a version requirement for the main application.
|
116
|
+
# Set the application version in config/initializers/wagon_app_version.rb.
|
117
|
+
# Gem::Requirement syntax is supported.
|
118
|
+
def app_requirement(requirement = nil)
|
119
|
+
if requirement
|
120
|
+
@app_requirement = Gem::Requirement.new(requirement)
|
121
|
+
else
|
122
|
+
@app_requirement ||= Gem::Requirement.new
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
110
126
|
end
|
111
127
|
end
|
112
128
|
|
data/lib/wagons/wagon_tasks.rake
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# These are the tasks included by the specific wagons
|
2
2
|
|
3
|
-
|
4
3
|
begin
|
5
4
|
require 'bundler/setup'
|
6
5
|
rescue LoadError
|
@@ -99,6 +98,8 @@ namespace :db do
|
|
99
98
|
|
100
99
|
desc "Display status of migrations"
|
101
100
|
app_task "migrate:status"
|
101
|
+
|
102
|
+
app_task "test:prepare"
|
102
103
|
end
|
103
104
|
|
104
105
|
|
@@ -106,12 +107,12 @@ Rake.application.invoke_task(:load_app)
|
|
106
107
|
|
107
108
|
|
108
109
|
namespace :app do
|
109
|
-
task :environment do
|
110
|
-
# set migrations paths only to core to have db:test:prepare work as desired
|
111
|
-
ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
|
112
|
-
end
|
113
|
-
|
114
110
|
namespace :db do
|
111
|
+
task :load_config do
|
112
|
+
# set migrations paths to core only to have db:test:prepare work as desired
|
113
|
+
ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
|
114
|
+
end
|
115
|
+
|
115
116
|
namespace :test do
|
116
117
|
# for sqlite, make sure to delete the test.sqlite3 from the main application
|
117
118
|
task :purge do
|
@@ -123,7 +124,8 @@ namespace :app do
|
|
123
124
|
end
|
124
125
|
end
|
125
126
|
|
126
|
-
# run wagon migrations and load seed data
|
127
|
+
# run wagon migrations and load seed data.
|
128
|
+
# append this to the regular app:db:test:prepare task.
|
127
129
|
task :prepare do
|
128
130
|
Rails.env = 'test'
|
129
131
|
dependencies = (wagon.all_dependencies + [wagon])
|