mbleigh-seed-fu 0.0.3 → 1.0.0

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/seed-fu.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'seed-fu'
3
- s.version = '0.0.3'
3
+ s.version = '1.0.0'
4
4
  s.date = '2008-08-16'
5
5
 
6
6
  s.summary = "Allows easier database seeding of tables."
@@ -1,16 +1,44 @@
1
1
  namespace :db do
2
- desc "Loads seed data from db/fixtures for the current environment."
2
+ desc <<-EOS
3
+ Loads seed data for the current environment. It will look for
4
+ ruby seed files in <RAILS_ROOT>/db/fixtures/ and
5
+ <RAILS_ROOT>/db/fixtures/<RAILS_ENV>/.
6
+
7
+ By default it will load any ruby files found. You can filter the files
8
+ loaded by passing in the SEED environment variable with a comma-delimited
9
+ list of patterns to include. Any files not matching the pattern will
10
+ not be loaded.
11
+
12
+ You can also change the directory where seed files are looked for
13
+ with the FIXTURE_PATH environment variable.
14
+
15
+ Examples:
16
+ # default, to load all seed files for the current environment
17
+ rake db:seed
18
+
19
+ # to load seed files matching orders or customers
20
+ rake db:seed SEED=orders,customers
21
+
22
+ # to load files from RAILS_ROOT/features/fixtures
23
+ rake db:seed FIXTURE_PATH=features/fixtures
24
+ EOS
3
25
  task :seed => :environment do
4
26
  fixture_path = ENV["FIXTURE_PATH"] ? ENV["FIXTURE_PATH"] : "db/fixtures"
5
- Dir[File.join(RAILS_ROOT, fixture_path, '*.rb')].sort.each { |fixture|
6
- puts "\n== Seeding from #{File.split(fixture).last} " + ("=" * (60 - (17 + File.split(fixture).last.length)))
7
- load fixture
8
- puts "=" * 60 + "\n"
9
- }
10
- Dir[File.join(RAILS_ROOT, fixture_path, RAILS_ENV, '*.rb')].sort.each { |fixture|
11
- puts "\n== [#{RAILS_ENV}] Seeding from #{File.split(fixture).last} " + ("=" * (60 - (20 + File.split(fixture).last.length + RAILS_ENV.length)))
12
- load fixture
13
- puts "=" * 60 + "\n"
14
- }
27
+
28
+ global_seed_files = Dir[File.join(RAILS_ROOT, fixture_path, '*.rb')].sort
29
+ env_specific_seed_files = Dir[File.join(RAILS_ROOT, fixture_path, RAILS_ENV, '*.rb')]
30
+ potential_seed_files = (global_seed_files + env_specific_seed_files).uniq
31
+
32
+ if ENV["SEED"]
33
+ filter = ENV["SEED"].gsub(/,/, "|")
34
+ potential_seed_files.reject!{ |file| true unless file =~ /#{filter}/ }
35
+ puts "\n == Filtering seed files against regexp: #{filter}"
36
+ end
37
+
38
+ potential_seed_files.each do |file|
39
+ pretty_name = file.sub("#{RAILS_ROOT}/", "")
40
+ puts "\n== Seed from #{pretty_name} " + ("=" * (60 - (17 + File.split(file).last.length)))
41
+ load file
42
+ end
15
43
  end
16
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbleigh-seed-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -14,6 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -1,6 +0,0 @@
1
- # Need this to get picked up by autotest?
2
- $:.push(File.join(File.dirname(__FILE__), %w[.. .. rspec]))
3
-
4
- Autotest.add_discovery do
5
- "rspec"
6
- end