engineer 0.2.1 → 0.2.2
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/README.rdoc
CHANGED
@@ -63,7 +63,7 @@ content:
|
|
63
63
|
Bundler.definition.dependencies.each do |dependency|
|
64
64
|
next if dependency.name == "engineer"
|
65
65
|
|
66
|
-
if (dependency.groups & [:default, :production
|
66
|
+
if (dependency.groups & [:default, :production]).any?
|
67
67
|
gem.add_dependency dependency.name, *dependency.requirement.as_list
|
68
68
|
else
|
69
69
|
gem.add_development_dependency dependency.name, *dependency.requirement.as_list
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/features/support/env.rb
CHANGED
@@ -1,94 +1,95 @@
|
|
1
|
-
|
1
|
+
if defined? <%= app_module %><%#%>::Engine
|
2
|
+
namespace "<%= app_name %><%#%>" do
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
# Migrate after schema in case there is no engine schema: at least we'll get the migrations.
|
5
|
+
task :install => %w{assets db:schema db:migrate db:migrate:seed}
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
desc "Import <%= app_name %><%#%>'s assets and new db migrations"
|
8
|
+
task :update => %w{assets db:migrate}
|
8
9
|
|
9
|
-
|
10
|
+
namespace :db do #<%# TODO: not everyone uses active record. %>
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def host_migration(new_migration_name, &block)
|
13
|
+
require 'rails/generators/active_record'
|
14
|
+
db_migrate = File.join Rails.root, *%w{db migrate}
|
15
|
+
mkdir_p db_migrate unless File.exists? db_migrate
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
# TODO Kill after https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4412
|
18
|
+
sleep 1 # wait for timestamp to change.
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
migration_number = ActiveRecord::Generators::Base.next_migration_number(db_migrate)
|
21
|
+
new_migration = File.join db_migrate, "#{migration_number}_#{new_migration_name}.rb"
|
22
|
+
tmp_migration = File.join Dir::tmpdir, "#{migration_number}_#{new_migration_name}.rb"
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
cp tmp_migration, new_migration
|
28
|
-
end
|
24
|
+
File.open(tmp_migration, "w") do |f|
|
25
|
+
f << block.call
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
host_migration new_migration_name do
|
32
|
-
block.call File.read original_file
|
28
|
+
cp tmp_migration, new_migration
|
33
29
|
end
|
34
|
-
end
|
35
|
-
|
36
|
-
desc "Import <%= app_name %><%#%>'s new db migrations"
|
37
|
-
task :migrate do
|
38
|
-
require 'rails/generators/active_record'
|
39
|
-
db_migrate = File.join Rails.root, *%w{db migrate}
|
40
30
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
# See if the host already has a schema migration.
|
46
|
-
last_migration_in_schema = migrations.reverse.detect do |migration|
|
47
|
-
name = File.basename(migration).match(/\d+_(.*)\.rb/)[1]
|
48
|
-
Dir[File.join(db_migrate, "[0-9]*_<%= app_name %><%#%>_schema_after_#{name}.rb")].any?
|
31
|
+
def import_migration(original_file, new_migration_name, &block)
|
32
|
+
host_migration new_migration_name do
|
33
|
+
block.call File.read original_file
|
34
|
+
end
|
49
35
|
end
|
50
36
|
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
desc "Import <%= app_name %><%#%>'s new db migrations"
|
38
|
+
task :migrate do
|
39
|
+
require 'rails/generators/active_record'
|
40
|
+
db_migrate = File.join Rails.root, *%w{db migrate}
|
54
41
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
new_name = "<%= app_name %><%#%>_#{old_name}"
|
59
|
-
|
60
|
-
# Skip this single migration if we already have it
|
61
|
-
next if Dir[File.join(db_migrate, "[0-9]*_#{new_name}.rb")].any?
|
42
|
+
# Consider the set of engine migrations, in chronological order.
|
43
|
+
migrations = Dir[File.join <%= app_module %><%#%>::Engine.root, *%w{db migrate [0-9]*_*.rb}]
|
44
|
+
migrations.sort!
|
62
45
|
|
63
|
-
|
64
|
-
|
46
|
+
# See if the host already has a schema migration.
|
47
|
+
last_migration_in_schema = migrations.reverse.detect do |migration|
|
48
|
+
name = File.basename(migration).match(/\d+_(.*)\.rb/)[1]
|
49
|
+
Dir[File.join(db_migrate, "[0-9]*_<%= app_name %><%#%>_schema_after_#{name}.rb")].any?
|
65
50
|
end
|
66
|
-
end
|
67
|
-
end
|
68
51
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
if File.exist? schema
|
73
|
-
migrations = Dir[File.join <%= app_module %><%#%>::Engine.root, *%w{db migrate [0-9]*_*.rb}]
|
74
|
-
latest_migration = migrations.sort.last
|
52
|
+
# If so, do not import any migrations implied by the schema
|
53
|
+
# (recall slice! *removes* the indicated range, leaving the rest.)
|
54
|
+
migrations.slice! 0..migrations.index(last_migration_in_schema) if last_migration_in_schema
|
75
55
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
"<%= app_name %><%#%>_schema"
|
81
|
-
end
|
56
|
+
# Of the remainder
|
57
|
+
migrations.each do |old_migration|
|
58
|
+
old_name = File.basename(old_migration).match(/\d+_(.*)\.rb/)[1]
|
59
|
+
new_name = "<%= app_name %><%#%>_#{old_name}"
|
82
60
|
|
83
|
-
|
84
|
-
|
85
|
-
schema_source.gsub! /\A.*^ActiveRecord::Schema.define\(:version => \d+\) do/m, ''
|
86
|
-
schema_source.strip!.gsub!(/^end\Z/m, '').strip!
|
61
|
+
# Skip this single migration if we already have it
|
62
|
+
next if Dir[File.join(db_migrate, "[0-9]*_#{new_name}.rb")].any?
|
87
63
|
|
88
|
-
|
89
|
-
|
64
|
+
import_migration old_migration, new_name do |migration_source|
|
65
|
+
migration_source.gsub "class #{old_name.camelize}", "class #{new_name.camelize}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
90
69
|
|
91
|
-
|
70
|
+
desc "Import <%= app_name %><%#%>'s schema as a db migration"
|
71
|
+
task :schema do
|
72
|
+
schema = File.join <%= app_module %><%#%>::Engine.root, *%w{db schema.rb}
|
73
|
+
if File.exist? schema
|
74
|
+
migrations = Dir[File.join <%= app_module %><%#%>::Engine.root, *%w{db migrate [0-9]*_*.rb}]
|
75
|
+
latest_migration = migrations.sort.last
|
76
|
+
|
77
|
+
migration_name = if latest_migration
|
78
|
+
latest_migration_name = File.basename(latest_migration).match(/^\d+_(.+)\.rb$/)[1]
|
79
|
+
"<%= app_name %><%#%>_schema_after_#{latest_migration_name}"
|
80
|
+
else
|
81
|
+
"<%= app_name %><%#%>_schema"
|
82
|
+
end
|
83
|
+
|
84
|
+
import_migration schema, migration_name do |schema_source|
|
85
|
+
# Strip schema declaration
|
86
|
+
schema_source.gsub! /\A.*^ActiveRecord::Schema.define\(:version => \d+\) do/m, ''
|
87
|
+
schema_source.strip!.gsub!(/^end\Z/m, '').strip!
|
88
|
+
|
89
|
+
# Indent everything 2 and strip trailing white space
|
90
|
+
schema_source.gsub!(/^/, ' ').gsub!(/[\t ]+$/, '')
|
91
|
+
|
92
|
+
# Wrap with migration class declaration
|
92
93
|
<<-EOF
|
93
94
|
class #{migration_name.camelize} < ActiveRecord::Migration
|
94
95
|
def self.up
|
@@ -96,14 +97,14 @@ class #{migration_name.camelize} < ActiveRecord::Migration
|
|
96
97
|
end
|
97
98
|
end
|
98
99
|
EOF
|
100
|
+
end
|
99
101
|
end
|
100
102
|
end
|
101
|
-
end
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
task "migrate:seed" do
|
105
|
+
migration_name = "<%= app_name %><%#%>_seed"
|
106
|
+
if File.exist? File.join(<%= app_module %><%#%>::Engine.root, 'db', 'seeds.rb')
|
107
|
+
host_migration migration_name do
|
107
108
|
<<-EOF
|
108
109
|
class #{migration_name.camelize} < ActiveRecord::Migration
|
109
110
|
def self.up
|
@@ -111,57 +112,58 @@ class #{migration_name.camelize} < ActiveRecord::Migration
|
|
111
112
|
end
|
112
113
|
end
|
113
114
|
EOF
|
115
|
+
end
|
114
116
|
end
|
115
117
|
end
|
116
|
-
end
|
117
118
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
desc "Load <%= app_name %><%#%>'s seed data"
|
120
|
+
task :seed => :environment do
|
121
|
+
seed_file = File.join(<%= app_module %><%#%>::Engine.root, 'db', 'seeds.rb')
|
122
|
+
load(seed_file) if File.exist?(seed_file)
|
123
|
+
end
|
123
124
|
|
124
|
-
|
125
|
+
end
|
125
126
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
127
|
+
desc "Link (or copy) <%= app_name %><%#%>'s static assets"
|
128
|
+
task :assets, [:copy] => :environment do |t, args|
|
129
|
+
engine_asset_path = File.join(
|
130
|
+
Rails.application.paths.public.to_a.first,
|
131
|
+
<%= app_module %><%#%>::Engine::ASSET_PREFIX)
|
132
|
+
|
133
|
+
rm_rf engine_asset_path
|
134
|
+
host_asset_path = <%= app_module %><%#%>::Engine.paths.public.to_a.first
|
135
|
+
|
136
|
+
link = lambda do
|
137
|
+
begin
|
138
|
+
ln_s host_asset_path, engine_asset_path
|
139
|
+
true
|
140
|
+
rescue NotImplementedError
|
141
|
+
false
|
142
|
+
end
|
141
143
|
end
|
142
|
-
end
|
143
144
|
|
144
|
-
|
145
|
+
copy = lambda { cp_r host_asset_path, engine_asset_path }
|
146
|
+
|
147
|
+
not args[:copy] and link.call or copy.call
|
148
|
+
end
|
145
149
|
|
146
|
-
not args[:copy] and link.call or copy.call
|
147
150
|
end
|
148
151
|
|
149
|
-
|
152
|
+
namespace :engines do
|
150
153
|
|
151
|
-
|
154
|
+
desc "Load seed data from all engines"
|
155
|
+
task "db:seed" => "<%= app_name %><%#%>:db:seed"
|
152
156
|
|
153
|
-
|
154
|
-
|
157
|
+
desc "Import new migrations from all engines"
|
158
|
+
task "db:migrate" => "<%= app_name %><%#%>:db:migrate"
|
155
159
|
|
156
|
-
|
157
|
-
|
160
|
+
desc "Link (or copy) static assets from all engines"
|
161
|
+
task :assets, [:copy] => "<%= app_name %><%#%>:assets"
|
158
162
|
|
159
|
-
|
160
|
-
|
163
|
+
desc "Import assets and new db migrations from all engines"
|
164
|
+
task :update => "<%= app_name %><%#%>:update"
|
161
165
|
|
162
|
-
|
163
|
-
task :update => "<%= app_name %><%#%>:update"
|
166
|
+
end
|
164
167
|
|
168
|
+
task "db:seed" => "engines:db:seed"
|
165
169
|
end
|
166
|
-
|
167
|
-
task "db:seed" => "engines:db:seed"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Phil Smith
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-28 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|