genesis 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,2 +1,2 @@
1
- rvm use ruby-1.8.7-p302@genesis --create
1
+ rvm use ruby-1.9.3-p392@genesis --create
2
2
  rvm info
@@ -30,7 +30,7 @@ seeding tools currently available.
30
30
 
31
31
  * Ruby 1.8
32
32
  * Rails 3
33
- * Rails 2
33
+ * Rails 2 (no generators)
34
34
 
35
35
  == TODO
36
36
 
@@ -50,25 +50,21 @@ seeding tools currently available.
50
50
 
51
51
  Run the prepare seeding generator to create a lib/tasks/genesis.rake file:
52
52
 
53
- rails generate prepare_genesis # Rails 3
54
- script/generate prepare_seeding # Rails 2
53
+ rails generate genesis:install # Rails 3
55
54
 
56
55
  Or to specify which environments to create:
57
56
 
58
- rails generate prepare_genesis [development,staging,production] # Rails 3
59
- script/generate prepare_seeding env:[development,staging,production] # Rails 2
57
+ rails generate genesis:install [development,staging,production] # Rails 3
60
58
 
61
59
  Generate a seed file:
62
60
 
63
- rails generate genesis create_users # Rails 3
64
- script/generate genesis create_users # Rails 2
61
+ rails generate genesis:seed create_users # Rails 3
65
62
 
66
63
  This will generate a seed file for you in the db/seeds directory.
67
64
 
68
65
  Generate a seed file in a specific environment folder:
69
66
 
70
- rails generate genesis create_users production # Rails 3
71
- script/generate genesis create_users production # Rails 2
67
+ rails generate genesis:seed create_users production # Rails 3
72
68
 
73
69
  This will generate a seed file for you in the db/seeds/production directory.
74
70
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  %w(
23
23
  gem-dandy
24
24
  rspec
25
- ruby-debug
25
+ ruby-debug19
26
26
  guard
27
27
  rb-fsevent
28
28
  growl
@@ -15,7 +15,6 @@ module Genesis
15
15
 
16
16
  def install_seeding
17
17
  envs.each { |env| empty_directory "db/seeds/#{env}" }
18
- copy_file 'genesis.rake', 'lib/tasks/genesis.rake'
19
18
  copy_file 'genesis_callbacks.rb', 'db/seeds/genesis_callbacks.rb'
20
19
  end
21
20
 
@@ -1,12 +1,11 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
- require 'genesis/active_record_extensions'
5
- require 'genesis/seeder'
6
- require 'genesis/schema_seed'
1
+ require 'genesis/railtie' if defined?( Rails )
7
2
 
8
3
  module Genesis
4
+
9
5
  SEEDS_ROOT = 'db/seeds'
10
- end
11
6
 
12
- ActiveRecord::Base.send :include, Genesis::ActiveRecordExtensions if defined? ActiveRecord::Base
7
+ autoload :ActiveRecordExtensions, 'genesis/active_record_extensions'
8
+ autoload :SchemaSeed, 'genesis/schema_seed'
9
+ autoload :Seeder, 'genesis/seeder'
10
+
11
+ end
@@ -0,0 +1,16 @@
1
+ require 'genesis'
2
+ require 'rails'
3
+
4
+ class Railtie < Rails::Railtie
5
+
6
+ initializer 'genesis.insert_into_active_record' do |app|
7
+ ActiveSupport.on_load :active_record do
8
+ ActiveRecord::Base.send :include, Genesis::ActiveRecordExtensions
9
+ end
10
+ end
11
+
12
+ rake_tasks do
13
+ Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
14
+ end
15
+
16
+ end
@@ -136,8 +136,7 @@ module Genesis
136
136
  log_entry_start( class_name )
137
137
  klass.send( @method )
138
138
  if @method == :up
139
- # SchemaSeed.create!( :version => version )
140
- ActiveRecord::Base.connection.execute( "INSERT INTO schema_seeds(`version`) VALUES('#{version}');" )
139
+ ActiveRecord::Base.connection.execute( "INSERT INTO schema_seeds(#{ActiveRecord::Base.connection.quote_column_name 'version'}) VALUES('#{version}');" )
141
140
  else
142
141
  schema_seed = SchemaSeed.find( :first, :conditions => { :version => version } )
143
142
  schema_seed.destroy unless schema_seed.nil?
@@ -1,4 +1,5 @@
1
1
  namespace :db do
2
+
2
3
  desc "Loads seed data for the current environment."
3
4
  task :genesis => :environment do
4
5
  Genesis::Seeder.verify_or_create_version_table
@@ -22,12 +23,31 @@ namespace :db do
22
23
  puts message( contexts, :using_contexts => using_contexts ), "", ""
23
24
  end
24
25
 
25
- desc "Drops and recreates all tables along with seeding the database"
26
+ desc "Recreates the databse by migrating down to VERSION=0 and then db:migrate and db:seed"
26
27
  task :mulligan => :environment do
27
- Rake::Task['db:migrate:reset'].invoke
28
+ raise 'Cannot seed production' if ENV['RAILS_ENV'] == 'production' || Rails.env.production?
29
+
30
+ ENV['VERSION']= '0'
31
+ Rake::Task['db:migrate'].invoke
32
+ Rake::Task['db:migrate'].reenable
33
+ ENV.delete 'VERSION'
34
+ Rake::Task["db:migrate"].invoke
35
+ Genesis::SchemaSeed.delete_all
28
36
  Rake::Task['db:genesis'].invoke
29
37
  end
30
38
 
39
+ namespace :mulligan do
40
+
41
+ desc 'Recreates database using db:migrate:reset and db:seed (helpful when an irreversible migration is blocking db:mulligan)'
42
+ task :reset => :environment do
43
+ raise 'Cannot seed production' if ENV['RAILS_ENV'] == 'production' || Rails.env.production?
44
+
45
+ Rake::Task['db:migrate:reset'].invoke
46
+ Rake::Task['db:genesis'].invoke
47
+ end
48
+
49
+ end
50
+
31
51
  desc "An alias for the db:genesis task"
32
52
  task :seed => :environment do
33
53
  Rake::Task['db:genesis'].invoke
@@ -38,8 +58,10 @@ namespace :db do
38
58
  Rake::Task['db:regenesis'].invoke
39
59
  end
40
60
 
41
- desc "Removes all data, runs migrations and then seeds the database"
61
+ desc "Removes all data and then seeds the database"
42
62
  task :regenesis => :environment do
63
+ raise 'Cannot seed production' if ENV['RAILS_ENV'] == 'production' || Rails.env.production?
64
+
43
65
  ActiveRecord::Base.connection.tables.select { |t| !['schema_migrations', 'schema_seeds', 'versions', 'sessions'].include?( t ) }.each do |table|
44
66
  puts "Emptying the #{table} table"
45
67
  klass = table.classify.to_s.constantize
@@ -49,11 +71,7 @@ namespace :db do
49
71
  puts ''
50
72
 
51
73
  Genesis::SchemaSeed.delete_all
52
- ActiveRecord::Base.connection.execute( 'DELETE FROM `versions`' )
53
- ActiveRecord::Base.connection.execute( 'DELETE FROM `sessions`' )
54
74
 
55
- Rake::Task['db:migrate'].invoke
56
- Rake::Task['db:test:prepare'].invoke
57
75
  Rake::Task['db:genesis'].invoke
58
76
  end
59
77
 
@@ -1,3 +1,3 @@
1
1
  module Genesis
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,159 +1,168 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: genesis
3
- version: !ruby/object:Gem::Version
4
- hash: 7
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 4
9
- - 0
10
- version: 1.4.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - C. Jason Harrelson
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-09-19 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2010-09-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: gem-dandy
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rspec
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
47
38
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: ruby-debug
51
39
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: ruby-debug19
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
61
54
  type: :development
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: guard
65
55
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
75
70
  type: :development
76
- version_requirements: *id004
77
- - !ruby/object:Gem::Dependency
78
- name: rb-fsevent
79
71
  prerelease: false
80
- requirement: &id005 !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-fsevent
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
89
86
  type: :development
90
- version_requirements: *id005
91
- - !ruby/object:Gem::Dependency
92
- name: growl
93
87
  prerelease: false
94
- requirement: &id006 !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
- version: "0"
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: growl
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
103
102
  type: :development
104
- version_requirements: *id006
105
- - !ruby/object:Gem::Dependency
106
- name: guard-rspec
107
103
  prerelease: false
108
- requirement: &id007 !ruby/object:Gem::Requirement
109
- none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- hash: 3
114
- segments:
115
- - 0
116
- version: "0"
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
117
118
  type: :development
118
- version_requirements: *id007
119
- - !ruby/object:Gem::Dependency
120
- name: rails
121
119
  prerelease: false
122
- requirement: &id008 !ruby/object:Gem::Requirement
123
- none: false
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- hash: 3
128
- segments:
129
- - 0
130
- version: "0"
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
131
134
  type: :development
132
- version_requirements: *id008
133
- - !ruby/object:Gem::Dependency
134
- name: genspec
135
135
  prerelease: false
136
- requirement: &id009 !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- hash: 3
142
- segments:
143
- - 0
144
- version: "0"
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: genspec
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
145
150
  type: :development
146
- version_requirements: *id009
147
- description: A data seeding solution for Ruby on Rails providing seeding facilities far more advanced than the current built in Ruby on Rails solution.
148
- email:
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: A data seeding solution for Ruby on Rails providing seeding facilities
159
+ far more advanced than the current built in Ruby on Rails solution.
160
+ email:
149
161
  - jason@lookforwardenterprises.com
150
162
  executables: []
151
-
152
163
  extensions: []
153
-
154
164
  extra_rdoc_files: []
155
-
156
- files:
165
+ files:
157
166
  - .document
158
167
  - .gitignore
159
168
  - .rspec
@@ -166,57 +175,53 @@ files:
166
175
  - genesis.gemspec
167
176
  - lib/generators/genesis/contexts/contexts_generator.rb
168
177
  - lib/generators/genesis/install/install_generator.rb
169
- - lib/generators/genesis/install/templates/genesis.rake
170
178
  - lib/generators/genesis/install/templates/genesis_callbacks.rb
171
179
  - lib/generators/genesis/seed/seed_generator.rb
172
180
  - lib/generators/genesis/seed/templates/migration.erb
173
181
  - lib/genesis.rb
174
182
  - lib/genesis/active_record_extensions.rb
175
183
  - lib/genesis/create_schema_seeds.rb
184
+ - lib/genesis/railtie.rb
176
185
  - lib/genesis/schema_seed.rb
177
186
  - lib/genesis/seeder.rb
187
+ - lib/genesis/tasks/genesis.rake
178
188
  - lib/genesis/version.rb
179
- - lib/tasks/genesis.rake
180
189
  - spec/generators/genesis/contexts/contexts_generator_spec.rb
181
190
  - spec/generators/genesis/install/install_generator_spec.rb
182
191
  - spec/generators/genesis/seed/seed_generator_spec.rb
183
192
  - spec/genesis_spec.rb
184
193
  - spec/spec_helper.rb
185
- has_rdoc: true
186
194
  homepage: https://github.com/midas/genesis
187
195
  licenses: []
188
-
189
196
  post_install_message:
190
197
  rdoc_options: []
191
-
192
- require_paths:
198
+ require_paths:
193
199
  - lib
194
- required_ruby_version: !ruby/object:Gem::Requirement
200
+ required_ruby_version: !ruby/object:Gem::Requirement
195
201
  none: false
196
- requirements:
197
- - - ">="
198
- - !ruby/object:Gem::Version
199
- hash: 3
200
- segments:
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ segments:
201
207
  - 0
202
- version: "0"
203
- required_rubygems_version: !ruby/object:Gem::Requirement
208
+ hash: -2473917623763783060
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
210
  none: false
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- hash: 3
209
- segments:
211
+ requirements:
212
+ - - ! '>='
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ segments:
210
216
  - 0
211
- version: "0"
217
+ hash: -2473917623763783060
212
218
  requirements: []
213
-
214
219
  rubyforge_project: genesis
215
- rubygems_version: 1.6.0
220
+ rubygems_version: 1.8.25
216
221
  signing_key:
217
222
  specification_version: 3
218
223
  summary: A data seeding solution for Ruby on Rails.
219
- test_files:
224
+ test_files:
220
225
  - spec/generators/genesis/contexts/contexts_generator_spec.rb
221
226
  - spec/generators/genesis/install/install_generator_spec.rb
222
227
  - spec/generators/genesis/seed/seed_generator_spec.rb
@@ -1,88 +0,0 @@
1
- namespace :db do
2
- desc "Loads seed data for the current environment."
3
- task :genesis => :environment do
4
- Genesis::Seeder.verify_or_create_version_table
5
- ignores = %w(genesis_common.rb)
6
- seeds = Dir[File.join( Rails.root, 'db', 'seeds', '*.rb' )] +
7
- Dir[File.join( Rails.root, 'db', 'seeds', Rails.env, '*.rb') ]
8
-
9
- contexts = ENV['CONTEXTS']
10
- unless contexts.nil? || contexts.empty?
11
- using_contexts = true
12
- contexts = expand_contexts if contexts == 'all'
13
- contexts.split( ',' ).each do |context|
14
- seeds += Dir[File.join( Rails.root, 'db', 'seeds', 'contexts', context, '*.rb' )]
15
- end
16
- end
17
-
18
-
19
-
20
- puts "", message( contexts, :using_contexts => using_contexts, :start => true ), ""
21
- Genesis::Seeder.run( seeds, ENV['VERSION'] || nil, ignores )
22
- puts message( contexts, :using_contexts => using_contexts ), "", ""
23
- end
24
-
25
- desc "Drops and recreates all tables along with seeding the database"
26
- task :mulligan => :environment do
27
- Rake::Task['db:migrate:reset'].invoke
28
- Rake::Task['db:genesis'].invoke
29
- end
30
-
31
- desc "An alias for the db:genesis task"
32
- task :seed => :environment do
33
- Rake::Task['db:genesis'].invoke
34
- end
35
-
36
- desc "An alias for the db:regenesis task"
37
- task :reseed => :environment do
38
- Rake::Task['db:regenesis'].invoke
39
- end
40
-
41
- desc "Removes all data, runs migrations and then seeds the database"
42
- task :regenesis => :environment do
43
- ActiveRecord::Base.connection.tables.select { |t| !['schema_migrations', 'schema_seeds', 'versions', 'sessions'].include?( t ) }.each do |table|
44
- puts "Emptying the #{table} table"
45
- klass = table.classify.to_s.constantize
46
- klass.delete_all
47
- end
48
-
49
- puts ''
50
-
51
- Genesis::SchemaSeed.delete_all
52
- ActiveRecord::Base.connection.execute( 'DELETE FROM `versions`' )
53
- ActiveRecord::Base.connection.execute( 'DELETE FROM `sessions`' )
54
-
55
- Rake::Task['db:migrate'].invoke
56
- Rake::Task['db:test:prepare'].invoke
57
- Rake::Task['db:genesis'].invoke
58
- end
59
-
60
- namespace :genesis do
61
- desc "Returns the current seed version from teh schema_seeds table"
62
- task :version => :environment do
63
- puts "[Genesis Seed Version] #{Genesis::Seeder.get_current_version}"
64
- end
65
- end
66
- end
67
-
68
- def seeds_root
69
- File.join( Rails.root, 'db', 'seeds' )
70
- end
71
-
72
- def contexts_root
73
- File.join( seeds_root, 'contexts' )
74
- end
75
-
76
- def expand_contexts
77
- Dir[File.join( contexts_root, '*' )].map { |d| d.split( '/' ).last }.join ','
78
- end
79
-
80
- def message( contexts, options={} )
81
- msg = options[:using_contexts] ?
82
- "*** #{start_or_end_word( options )} seeding (contexts: #{contexts.split(',').join(', ')})" :
83
- "*** #{start_or_end_word( options )} seeding"
84
- end
85
-
86
- def start_or_end_word( options )
87
- return options[:start] ? 'Start' : 'End'
88
- end