engineer 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
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, :staging]).any?
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
1
+ 0.2.2
@@ -2,7 +2,7 @@
2
2
  # http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/
3
3
 
4
4
  require "rubygems"
5
- gem "railties", ">= 3.0.0.beta2"
5
+ gem "railties", ">= 3.0.0.beta3"
6
6
 
7
7
  require "fileutils"
8
8
  require "tempfile"
@@ -1,94 +1,95 @@
1
- namespace "<%= app_name %><%#%>" do
1
+ if defined? <%= app_module %><%#%>::Engine
2
+ namespace "<%= app_name %><%#%>" do
2
3
 
3
- # Migrate after schema in case there is no engine schema: at least we'll get the migrations.
4
- task :install => %w{assets db:schema db:migrate db:migrate:seed}
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
- desc "Import <%= app_name %><%#%>'s assets and new db migrations"
7
- task :update => %w{assets db:migrate}
7
+ desc "Import <%= app_name %><%#%>'s assets and new db migrations"
8
+ task :update => %w{assets db:migrate}
8
9
 
9
- namespace :db do #<%# TODO: not everyone uses active record. %>
10
+ namespace :db do #<%# TODO: not everyone uses active record. %>
10
11
 
11
- def host_migration(new_migration_name, &block)
12
- require 'rails/generators/active_record'
13
- db_migrate = File.join Rails.root, *%w{db migrate}
14
- mkdir_p db_migrate unless File.exists? db_migrate
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
- # TODO Kill after https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4412
17
- sleep 1 # wait for timestamp to change.
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
- migration_number = ActiveRecord::Generators::Base.next_migration_number(db_migrate)
20
- new_migration = File.join db_migrate, "#{migration_number}_#{new_migration_name}.rb"
21
- tmp_migration = File.join Dir::tmpdir, "#{migration_number}_#{new_migration_name}.rb"
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
- File.open(tmp_migration, "w") do |f|
24
- f << block.call
25
- end
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
- def import_migration(original_file, new_migration_name, &block)
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
- # Consider the set of engine migrations, in chronological order.
42
- migrations = Dir[File.join <%= app_module %><%#%>::Engine.root, *%w{db migrate [0-9]*_*.rb}]
43
- migrations.sort!
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
- # If so, do not import any migrations implied by the schema
52
- # (recall slice! *removes* the indicated range, leaving the rest.)
53
- migrations.slice! 0..migrations.index(last_migration_in_schema) if last_migration_in_schema
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
- # Of the remainder
56
- migrations.each do |old_migration|
57
- old_name = File.basename(old_migration).match(/\d+_(.*)\.rb/)[1]
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
- import_migration old_migration, new_name do |migration_source|
64
- migration_source.gsub "class #{old_name.camelize}", "class #{new_name.camelize}"
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
- desc "Import <%= app_name %><%#%>'s schema as a db migration"
70
- task :schema do
71
- schema = File.join <%= app_module %><%#%>::Engine.root, *%w{db schema.rb}
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
- migration_name = if latest_migration
77
- latest_migration_name = File.basename(latest_migration).match(/^\d+_(.+)\.rb$/)[1]
78
- "<%= app_name %><%#%>_schema_after_#{latest_migration_name}"
79
- else
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
- import_migration schema, migration_name do |schema_source|
84
- # Strip schema declaration
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
- # Indent everything 2 and strip trailing white space
89
- schema_source.gsub!(/^/, ' ').gsub!(/[\t ]+$/, '')
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
- # Wrap with migration class declaration
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
- task "migrate:seed" do
104
- migration_name = "<%= app_name %><%#%>_seed"
105
- if File.exist? File.join(<%= app_module %><%#%>::Engine.root, 'db', 'seeds.rb')
106
- host_migration migration_name do
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
- desc "Load <%= app_name %><%#%>'s seed data"
119
- task :seed => :environment do
120
- seed_file = File.join(<%= app_module %><%#%>::Engine.root, 'db', 'seeds.rb')
121
- load(seed_file) if File.exist?(seed_file)
122
- end
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
- end
125
+ end
125
126
 
126
- desc "Link (or copy) <%= app_name %><%#%>'s static assets"
127
- task :assets, [:copy] => :environment do |t, args|
128
- engine_asset_path = File.join(
129
- Rails.application.paths.public.to_a.first,
130
- <%= app_module %><%#%>::Engine::ASSET_PREFIX)
131
-
132
- rm_rf engine_asset_path
133
- host_asset_path = <%= app_module %><%#%>::Engine.paths.public.to_a.first
134
-
135
- link = lambda do
136
- begin
137
- ln_s host_asset_path, engine_asset_path
138
- true
139
- rescue NotImplementedError
140
- false
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
- copy = lambda { cp_r host_asset_path, engine_asset_path }
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
- end
152
+ namespace :engines do
150
153
 
151
- namespace :engines do
154
+ desc "Load seed data from all engines"
155
+ task "db:seed" => "<%= app_name %><%#%>:db:seed"
152
156
 
153
- desc "Load seed data from all engines"
154
- task "db:seed" => "<%= app_name %><%#%>:db:seed"
157
+ desc "Import new migrations from all engines"
158
+ task "db:migrate" => "<%= app_name %><%#%>:db:migrate"
155
159
 
156
- desc "Import new migrations from all engines"
157
- task "db:migrate" => "<%= app_name %><%#%>:db:migrate"
160
+ desc "Link (or copy) static assets from all engines"
161
+ task :assets, [:copy] => "<%= app_name %><%#%>:assets"
158
162
 
159
- desc "Link (or copy) static assets from all engines"
160
- task :assets, [:copy] => "<%= app_name %><%#%>:assets"
163
+ desc "Import assets and new db migrations from all engines"
164
+ task :update => "<%= app_name %><%#%>:update"
161
165
 
162
- desc "Import assets and new db migrations from all engines"
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
- - 1
9
- version: 0.2.1
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-16 00:00:00 -07:00
17
+ date: 2010-05-28 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency