seed_dump 3.2.2 → 3.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b4e4cffee80f290d4cfd89e9f9e2e2cd4f13934
4
- data.tar.gz: ca16d9c36607e1ebdfee10c23e76b08e8ce499b4
3
+ metadata.gz: 1bfcd65c34467c044f875ef084729c6a2e0cd442
4
+ data.tar.gz: 7fa4cfbe1c3b30fd5e7be8ec46e4c683309a96da
5
5
  SHA512:
6
- metadata.gz: 6909a0dc975fe479d0fb863058a50a40452f688a99460fff9e737cda91b143f07970271e14ff055190e243c922690f7788b736d15c9125705ea4df2b2c5b66a1
7
- data.tar.gz: 453a49a2c934461af62aac6b5d9a4dce8774e82ed6826690da4c64c5ba46bdfee218d191cd91636a50988a1c635c2ab4d09d22deb5ad43b60d4c92c0c8843256
6
+ metadata.gz: 098d59994240e35e24642d36ec390e6cb8edf963f639e3394c0e6c837e52a761e01fdd72cf90f55071c3fd49ff1ad15e8caf550578c95c29b824bb8837fdce77
7
+ data.tar.gz: fd1e6c948eb825f2c627f4bc8e7887b8170ca301525668f191af94f83d2015ca1b62b938411f3010ab0c1c2776505df33070504e883d1d7b2f98a8abf0f1d60a
data/README.md CHANGED
@@ -13,89 +13,99 @@ Installation
13
13
  ------------
14
14
 
15
15
  Add it to your Gemfile with:
16
-
17
- gem 'seed_dump'
18
-
16
+ ```ruby
17
+ gem 'seed_dump'
18
+ ```
19
19
  Or install it by hand:
20
-
21
- $ gem install seed_dump
22
-
20
+ ```sh
21
+ $ gem install seed_dump
22
+ ```
23
23
  Examples
24
24
  --------
25
25
 
26
26
  ### Rake task
27
27
 
28
28
  Dump all data directly to `db/seeds.rb`:
29
-
30
- $ rake db:seed:dump
31
-
29
+ ```sh
30
+ $ rake db:seed:dump
31
+ ```
32
32
  Result:
33
-
34
- Product.create!([
35
- {category_id: 1, description: "Long Sleeve Shirt", name: "Long Sleeve Shirt"},
36
- {category_id: 3, description: "Plain White Tee Shirt", name: "Plain T-Shirt"}
37
- ])
38
- User.create!([
39
- {password: "123456", username: "test_1"},
40
- {password: "234567", username: "test_2"}
41
- ])
33
+ ```ruby
34
+ Product.create!([
35
+ { category_id: 1, description: "Long Sleeve Shirt", name: "Long Sleeve Shirt" },
36
+ { category_id: 3, description: "Plain White Tee Shirt", name: "Plain T-Shirt" }
37
+ ])
38
+ User.create!([
39
+ { password: "123456", username: "test_1" },
40
+ { password: "234567", username: "test_2" }
41
+ ])
42
+ ```
42
43
 
43
44
  Dump only data from the users table and dump a maximum of 1 record:
44
-
45
- $ rake db:seed:dump MODELS=User LIMIT=1
45
+ ```sh
46
+ $ rake db:seed:dump MODELS=User LIMIT=1
47
+ ```
46
48
 
47
49
  Result:
48
-
49
- User.create!([
50
- {password: "123456", username: "test_1"}
51
- ])
50
+ ```ruby
51
+ User.create!([
52
+ { password: "123456", username: "test_1" }
53
+ ])
54
+ ```
52
55
 
53
56
  Append to `db/seeds.rb` instead of overwriting it:
54
-
55
- rake db:seed:dump APPEND=true
57
+ ```sh
58
+ rake db:seed:dump APPEND=true
59
+ ```
56
60
 
57
61
  Use another output file instead of `db/seeds.rb`:
58
-
59
- rake db:seed:dump FILE=db/seeds/users.rb
62
+ ```sh
63
+ rake db:seed:dump FILE=db/seeds/users.rb
64
+ ```
60
65
 
61
66
  Exclude `name` and `age` from the dump:
62
-
63
- rake db:seed:dump EXCLUDE=name,age
67
+ ```sh
68
+ rake db:seed:dump EXCLUDE=name,age
69
+ ```
64
70
 
65
71
  There are more options that can be set— see below for all of them.
66
72
 
67
73
  ### Console
68
74
 
69
75
  Output a dump of all User records:
70
-
71
- irb(main):001:0> puts SeedDump.dump(User)
72
- User.create!([
73
- {password: "123456", username: "test_1"},
74
- {password: "234567", username: "test_2"}
75
- ])
76
+ ```ruby
77
+ irb(main):001:0> puts SeedDump.dump(User)
78
+ User.create!([
79
+ { password: "123456", username: "test_1" },
80
+ { password: "234567", username: "test_2" }
81
+ ])
82
+ ```
76
83
 
77
84
  Write the dump to a file:
78
-
79
- irb(main):002:0> SeedDump.dump(User, file: 'db/seeds.rb')
85
+ ```ruby
86
+ irb(main):002:0> SeedDump.dump(User, file: 'db/seeds.rb')
87
+ ```
80
88
 
81
89
  Append the dump to a file:
82
-
83
- irb(main):003:0> SeedDump.dump(User, file: 'db/seeds.rb', append: true)
90
+ ```ruby
91
+ irb(main):003:0> SeedDump.dump(User, file: 'db/seeds.rb', append: true)
92
+ ```
84
93
 
85
94
  Exclude `name` and `age` from the dump:
86
-
87
- irb(main):004:0> SeedDump.dump(User, exclude: [:name, :age])
95
+ ```ruby
96
+ irb(main):004:0> SeedDump.dump(User, exclude: [:name, :age])
97
+ ```
88
98
 
89
99
  Options are specified as a Hash for the second argument.
90
100
 
91
101
  In the console, any relation of ActiveRecord rows can be dumped (not individual objects though)
92
-
93
- irb(main):001:0> puts SeedDump.dump(User.where(is_admin: false)
94
- User.create!([
95
- {password: "123456", username: "test_1", is_admin: false},
96
- {password: "234567", username: "test_2", is_admin: false}
97
- ])
98
-
102
+ ```ruby
103
+ irb(main):001:0> puts SeedDump.dump(User.where(is_admin: false))
104
+ User.create!([
105
+ { password: "123456", username: "test_1", is_admin: false },
106
+ { password: "234567", username: "test_2", is_admin: false }
107
+ ])
108
+ ```
99
109
 
100
110
  Options
101
111
  -------
@@ -106,7 +116,7 @@ Options are common to both the Rake task and the console, except where noted.
106
116
 
107
117
  `batch_size`: Controls the number of records that are written to file at a given time. Default: 1000. If you're running out of memory when dumping, try decreasing this. If things are dumping too slow, trying increasing this.
108
118
 
109
- `exclude`: Attributes to be excluded from the dump.Pass a comma-separated list to the Rake task (i.e. `name,age`) and an array on the console (i.e. `[:name, :age]`). Default: `[:id, :created_at, :updated_at]` (this default can be overridden by just setting this option)
119
+ `exclude`: Attributes to be excluded from the dump. Pass a comma-separated list to the Rake task (i.e. `name,age`) and an array on the console (i.e. `[:name, :age]`). Default: `[:id, :created_at, :updated_at]`.
110
120
 
111
121
  `file`: Write to the specified output file. The Rake task default is `db/seeds.rb`. The console returns the dump as a string by default.
112
122
 
@@ -114,4 +124,8 @@ Options are common to both the Rake task and the console, except where noted.
114
124
 
115
125
  `limit`: Dump no more than this amount of data. Default: no limit. Rake task only. In the console just pass in an ActiveRecord::Relation with the appropriate limit (e.g. `SeedDump.dump(User.limit(5))`).
116
126
 
127
+ `conditions`: Dump only specific records. In the console just pass in an ActiveRecord::Relation with the appropriate conditions (e.g. `SeedDump.dump(User.where(state: :active))`).
128
+
117
129
  `model[s]`: Restrict the dump to the specified comma-separated list of models. Default: all models. If you are using a Rails engine you can dump a specific model by passing "EngineName::ModelName". Rake task only. Example: `rake db:seed:dump MODELS="User, Position, Function"`
130
+
131
+ `models_exclude`: Exclude the specified comma-separated list of models from the dump. Default: no models excluded. Rake task only. Example: `rake db:seed:dump MODELS_EXCLUDE="User"`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.2.3
@@ -1,3 +1,4 @@
1
+ require 'ipaddr'
1
2
  require 'seed_dump/dump_methods/enumeration'
2
3
  require 'seed_dump/dump_methods'
3
4
  require 'seed_dump/environment'
@@ -20,6 +20,13 @@ class SeedDump
20
20
 
21
21
  append = (env['APPEND'] == 'true')
22
22
 
23
+ models_exclude_env = env['MODELS_EXCLUDE']
24
+ if models_exclude_env
25
+ models_exclude_env.split(',')
26
+ .collect {|x| x.strip.underscore.singularize.camelize.constantize }
27
+ .each { |exclude| models.delete(exclude) }
28
+ end
29
+
23
30
  models.each do |model|
24
31
  model = model.limit(env['LIMIT'].to_i) if env['LIMIT']
25
32
 
@@ -35,4 +42,3 @@ class SeedDump
35
42
  end
36
43
  end
37
44
  end
38
-
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: seed_dump 3.2.2 ruby lib
5
+ # stub: seed_dump 3.2.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "seed_dump"
9
- s.version = "3.2.2"
9
+ s.version = "3.2.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Rob Halff", "Ryan Oblak"]
14
- s.date = "2015-03-03"
14
+ s.date = "2015-12-06"
15
15
  s.description = "Dump (parts) of your database to db/seeds.rb to get a headstart creating a meaningful seeds.rb file"
16
16
  s.email = "rroblak@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  ]
42
42
  s.homepage = "https://github.com/rroblak/seed_dump"
43
43
  s.licenses = ["MIT"]
44
- s.rubygems_version = "2.4.3"
44
+ s.rubygems_version = "2.4.5"
45
45
  s.summary = "{Seed Dumper for Rails}"
46
46
 
47
47
  if s.respond_to? :specification_version then
@@ -111,6 +111,16 @@ describe SeedDump do
111
111
  end
112
112
  end
113
113
 
114
+ describe "MODELS_EXCLUDE" do
115
+ it "should dump all non-empty models except the specified models" do
116
+ FactoryGirl.create(:another_sample)
117
+
118
+ SeedDump.should_receive(:dump).with(Sample, anything)
119
+
120
+ SeedDump.dump_using_environment('MODELS_EXCLUDE' => 'AnotherSample')
121
+ end
122
+ end
123
+
114
124
  it 'should run ok without ActiveRecord::SchemaMigration being set (needed for Rails Engines)' do
115
125
  schema_migration = ActiveRecord::SchemaMigration
116
126
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seed_dump
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Halff
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-03 00:00:00.000000000 Z
12
+ date: 2015-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.4.3
146
+ rubygems_version: 2.4.5
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: "{Seed Dumper for Rails}"