seedable 0.0.1
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/.gitignore +10 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +7 -0
- data/Appraisals +9 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE +21 -0
- data/README.rdoc +95 -0
- data/Rakefile +28 -0
- data/db/schema.rb +34 -0
- data/gemfiles/rails-3.1.0.gemfile +7 -0
- data/gemfiles/rails-3.1.0.gemfile.lock +149 -0
- data/gemfiles/rails-master.gemfile +7 -0
- data/gemfiles/rails-master.gemfile.lock +153 -0
- data/lib/seedable.rb +19 -0
- data/lib/seedable/core_ext.rb +66 -0
- data/lib/seedable/exporter.rb +163 -0
- data/lib/seedable/helpers.rb +144 -0
- data/lib/seedable/importer.rb +55 -0
- data/lib/seedable/object_tracker.rb +45 -0
- data/lib/seedable/version.rb +5 -0
- data/seedable.gemspec +44 -0
- data/spec/database.yml +7 -0
- data/spec/models/filtered_garage_spec.rb +22 -0
- data/spec/models/garage_spec.rb +197 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/support/factories.rb +23 -0
- data/spec/support/models.rb +43 -0
- metadata +271 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@seedable --create
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Christopher Meiklejohn
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
= Seedable
|
2
|
+
|
3
|
+
Data import and export for rails, to assist in seeding development
|
4
|
+
databases from production.
|
5
|
+
|
6
|
+
== What is Seedable?
|
7
|
+
|
8
|
+
Seedable is a mixin to select groups of objects, and export them via
|
9
|
+
serialized JSON, to be reimported later. The goal, is less to maintain
|
10
|
+
a consistent database state, but for quick dumping and restoring of data
|
11
|
+
between environments, to seed your database.
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
Using Seedable is easy!
|
16
|
+
|
17
|
+
=== How do I include it?
|
18
|
+
|
19
|
+
Add the gem.
|
20
|
+
|
21
|
+
gem 'seedable'
|
22
|
+
|
23
|
+
Include the module:
|
24
|
+
|
25
|
+
include Seedable
|
26
|
+
|
27
|
+
In the models you want to export together, place the following:
|
28
|
+
|
29
|
+
seedable
|
30
|
+
|
31
|
+
=== Exporting records
|
32
|
+
|
33
|
+
To export, call:
|
34
|
+
|
35
|
+
json = @garage.to_seedable
|
36
|
+
|
37
|
+
By default, seedable will traverse all active\_record associations and
|
38
|
+
export all of their attributes. To exclude associations, do the following:
|
39
|
+
|
40
|
+
seedable :include_associations => [:cars, :bikes]
|
41
|
+
|
42
|
+
You can also call it after the fact:
|
43
|
+
|
44
|
+
Garage.include_associations([:cars])
|
45
|
+
|
46
|
+
To filter attributes:
|
47
|
+
|
48
|
+
seedable :filter_attributes => [:id]
|
49
|
+
|
50
|
+
You can also call it after the fact:
|
51
|
+
|
52
|
+
Garage.filter_attributes([:id])
|
53
|
+
|
54
|
+
You can also export an array of disperse object types:
|
55
|
+
|
56
|
+
[@garage, @car, @garage2, @bike].to_seedable
|
57
|
+
|
58
|
+
=== Importing records
|
59
|
+
|
60
|
+
To import:
|
61
|
+
|
62
|
+
Garage.from_seedable(json)
|
63
|
+
|
64
|
+
or, if you have JSON from a unknown object type and want it to return
|
65
|
+
the proper object type:
|
66
|
+
|
67
|
+
Seedable.from_seedable(garage_json) # Returns Garage object.
|
68
|
+
|
69
|
+
or, an array of different object types:
|
70
|
+
|
71
|
+
json = [@garage, @car, @garage2, @bike].to_seedable
|
72
|
+
Seedable.from_seedable(json) # Returns array of [Garage, Car, Garage, Bike]
|
73
|
+
|
74
|
+
== Caveats
|
75
|
+
|
76
|
+
This is the first release, and yes, there are a bunch of caveats.
|
77
|
+
|
78
|
+
=== Compatibility
|
79
|
+
|
80
|
+
1. Compatible and tested under rails 3.1 and rails-master.
|
81
|
+
2. Compatible and tested under ruby 1.9.2.
|
82
|
+
|
83
|
+
=== Exporting with primary keys
|
84
|
+
|
85
|
+
1. Importing objects with associated objects by primary key will only
|
86
|
+
work on rails master. This is because the code relies on mass
|
87
|
+
assignment changes/abstractions destined for rails-3.2.x.
|
88
|
+
|
89
|
+
== License
|
90
|
+
|
91
|
+
Seedable is Copyright © 2011 Christopher Meiklejohn. It is free software, and may be redistributed under the terms specified in the LICENSE file.
|
92
|
+
|
93
|
+
== About
|
94
|
+
|
95
|
+
The seedable gem was written by {Christopher Meiklejohn}[mailto:cmeiklejohn@swipely.com] from {Swipely, Inc.}[http://www.swipely.com].
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'rake'
|
7
|
+
require 'rdoc/task'
|
8
|
+
require 'rubygems/package_task'
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
require 'appraisal'
|
11
|
+
|
12
|
+
desc "Default: run the specs"
|
13
|
+
task :default => [:all]
|
14
|
+
|
15
|
+
desc 'Test the plugin under all supported Rails versions.'
|
16
|
+
task :all => ["appraisal:install"] do |t|
|
17
|
+
exec('rake appraisal spec')
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec::Core::RakeTask.new do |t|
|
21
|
+
t.pattern = 'spec/**/*_spec.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
RDoc::Task.new do |rdoc|
|
25
|
+
rdoc.main = "README.rdoc"
|
26
|
+
rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
27
|
+
rdoc.options << '-f' << 'horo'
|
28
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define do
|
4
|
+
self.verbose = false
|
5
|
+
|
6
|
+
create_table :garages, :force => true do |t|
|
7
|
+
t.string :name
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table :filtered_garages, :force => true do |t|
|
12
|
+
t.string :name
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table :cars, :force => true do |t|
|
17
|
+
t.string :make
|
18
|
+
t.string :model
|
19
|
+
t.integer :garage_id
|
20
|
+
t.timestamps
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table :bikes, :force => true do |t|
|
24
|
+
t.integer :garage_id
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table :drivers, :force => true do |t|
|
29
|
+
t.string :name
|
30
|
+
t.integer :car_id
|
31
|
+
t.timestamps
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/cmeiklejohn/Repositories/seedable
|
3
|
+
specs:
|
4
|
+
seedable (0.0.1)
|
5
|
+
rails (>= 3.1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (3.1.0)
|
11
|
+
actionpack (= 3.1.0)
|
12
|
+
mail (~> 2.3.0)
|
13
|
+
actionpack (3.1.0)
|
14
|
+
activemodel (= 3.1.0)
|
15
|
+
activesupport (= 3.1.0)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
i18n (~> 0.6)
|
19
|
+
rack (~> 1.3.2)
|
20
|
+
rack-cache (~> 1.0.3)
|
21
|
+
rack-mount (~> 0.8.2)
|
22
|
+
rack-test (~> 0.6.1)
|
23
|
+
sprockets (~> 2.0.0)
|
24
|
+
activemodel (3.1.0)
|
25
|
+
activesupport (= 3.1.0)
|
26
|
+
bcrypt-ruby (~> 3.0.0)
|
27
|
+
builder (~> 3.0.0)
|
28
|
+
i18n (~> 0.6)
|
29
|
+
activerecord (3.1.0)
|
30
|
+
activemodel (= 3.1.0)
|
31
|
+
activesupport (= 3.1.0)
|
32
|
+
arel (~> 2.2.1)
|
33
|
+
tzinfo (~> 0.3.29)
|
34
|
+
activeresource (3.1.0)
|
35
|
+
activemodel (= 3.1.0)
|
36
|
+
activesupport (= 3.1.0)
|
37
|
+
activesupport (3.1.0)
|
38
|
+
multi_json (~> 1.0)
|
39
|
+
appraisal (0.3.8)
|
40
|
+
bundler
|
41
|
+
rake
|
42
|
+
arel (2.2.1)
|
43
|
+
bcrypt-ruby (3.0.0)
|
44
|
+
builder (3.0.0)
|
45
|
+
diesel (0.1.5)
|
46
|
+
railties
|
47
|
+
diff-lcs (1.1.3)
|
48
|
+
erubis (2.7.0)
|
49
|
+
factory_girl (2.0.5)
|
50
|
+
factory_girl_rails (1.1.0)
|
51
|
+
factory_girl (~> 2.0.0)
|
52
|
+
railties (>= 3.0.0)
|
53
|
+
ffi (1.0.9)
|
54
|
+
guard (0.6.3)
|
55
|
+
thor (~> 0.14.6)
|
56
|
+
guard-rspec (0.4.3)
|
57
|
+
guard (>= 0.4.0)
|
58
|
+
hike (1.2.1)
|
59
|
+
horo (1.0.3)
|
60
|
+
rdoc (>= 2.5)
|
61
|
+
i18n (0.6.0)
|
62
|
+
libnotify (0.5.7)
|
63
|
+
mail (2.3.0)
|
64
|
+
i18n (>= 0.4.0)
|
65
|
+
mime-types (~> 1.16)
|
66
|
+
treetop (~> 1.4.8)
|
67
|
+
mime-types (1.16)
|
68
|
+
mocha (0.9.12)
|
69
|
+
multi_json (1.0.3)
|
70
|
+
polyglot (0.3.2)
|
71
|
+
rack (1.3.2)
|
72
|
+
rack-cache (1.0.3)
|
73
|
+
rack (>= 0.4)
|
74
|
+
rack-mount (0.8.3)
|
75
|
+
rack (>= 1.0.0)
|
76
|
+
rack-ssl (1.3.2)
|
77
|
+
rack
|
78
|
+
rack-test (0.6.1)
|
79
|
+
rack (>= 1.0)
|
80
|
+
rails (3.1.0)
|
81
|
+
actionmailer (= 3.1.0)
|
82
|
+
actionpack (= 3.1.0)
|
83
|
+
activerecord (= 3.1.0)
|
84
|
+
activeresource (= 3.1.0)
|
85
|
+
activesupport (= 3.1.0)
|
86
|
+
bundler (~> 1.0)
|
87
|
+
railties (= 3.1.0)
|
88
|
+
railties (3.1.0)
|
89
|
+
actionpack (= 3.1.0)
|
90
|
+
activesupport (= 3.1.0)
|
91
|
+
rack-ssl (~> 1.3.2)
|
92
|
+
rake (>= 0.8.7)
|
93
|
+
rdoc (~> 3.4)
|
94
|
+
thor (~> 0.14.6)
|
95
|
+
rake (0.9.2)
|
96
|
+
rb-inotify (0.8.6)
|
97
|
+
ffi (>= 0.5.0)
|
98
|
+
rdoc (3.9.4)
|
99
|
+
rspec (2.6.0)
|
100
|
+
rspec-core (~> 2.6.0)
|
101
|
+
rspec-expectations (~> 2.6.0)
|
102
|
+
rspec-mocks (~> 2.6.0)
|
103
|
+
rspec-core (2.6.4)
|
104
|
+
rspec-expectations (2.6.0)
|
105
|
+
diff-lcs (~> 1.1.2)
|
106
|
+
rspec-mocks (2.6.0)
|
107
|
+
rspec-rails (2.6.1)
|
108
|
+
actionpack (~> 3.0)
|
109
|
+
activesupport (~> 3.0)
|
110
|
+
railties (~> 3.0)
|
111
|
+
rspec (~> 2.6.0)
|
112
|
+
simplecov (0.4.2)
|
113
|
+
simplecov-html (~> 0.4.4)
|
114
|
+
simplecov-html (0.4.5)
|
115
|
+
sprockets (2.0.0)
|
116
|
+
hike (~> 1.2)
|
117
|
+
rack (~> 1.0)
|
118
|
+
tilt (!= 1.3.0, ~> 1.1)
|
119
|
+
sqlite3 (1.3.4)
|
120
|
+
thor (0.14.6)
|
121
|
+
tilt (1.3.3)
|
122
|
+
timecop (0.3.5)
|
123
|
+
treetop (1.4.10)
|
124
|
+
polyglot
|
125
|
+
polyglot (>= 0.3.1)
|
126
|
+
tzinfo (0.3.29)
|
127
|
+
|
128
|
+
PLATFORMS
|
129
|
+
ruby
|
130
|
+
|
131
|
+
DEPENDENCIES
|
132
|
+
appraisal (~> 0.3.5)
|
133
|
+
bundler (~> 1.0.0)
|
134
|
+
diesel
|
135
|
+
factory_girl
|
136
|
+
factory_girl_rails
|
137
|
+
guard
|
138
|
+
guard-rspec
|
139
|
+
horo
|
140
|
+
libnotify
|
141
|
+
mocha
|
142
|
+
rails (= 3.1.0)
|
143
|
+
rb-inotify
|
144
|
+
rspec
|
145
|
+
rspec-rails
|
146
|
+
seedable!
|
147
|
+
simplecov
|
148
|
+
sqlite3
|
149
|
+
timecop
|
@@ -0,0 +1,153 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/rails/rails.git
|
3
|
+
revision: 67790644372ad3a771810f1d6d99687d795789ea
|
4
|
+
specs:
|
5
|
+
actionmailer (3.2.0.beta)
|
6
|
+
actionpack (= 3.2.0.beta)
|
7
|
+
mail (~> 2.3.0)
|
8
|
+
actionpack (3.2.0.beta)
|
9
|
+
activemodel (= 3.2.0.beta)
|
10
|
+
activesupport (= 3.2.0.beta)
|
11
|
+
builder (~> 3.0.0)
|
12
|
+
erubis (~> 2.7.0)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
rack (~> 1.3.2)
|
15
|
+
rack-cache (~> 1.0.3)
|
16
|
+
rack-mount (~> 0.8.2)
|
17
|
+
rack-test (~> 0.6.1)
|
18
|
+
sprockets (~> 2.0.0)
|
19
|
+
activemodel (3.2.0.beta)
|
20
|
+
activesupport (= 3.2.0.beta)
|
21
|
+
builder (~> 3.0.0)
|
22
|
+
i18n (~> 0.6)
|
23
|
+
activerecord (3.2.0.beta)
|
24
|
+
activemodel (= 3.2.0.beta)
|
25
|
+
activesupport (= 3.2.0.beta)
|
26
|
+
arel (~> 2.2.1)
|
27
|
+
tzinfo (~> 0.3.29)
|
28
|
+
activeresource (3.2.0.beta)
|
29
|
+
activemodel (= 3.2.0.beta)
|
30
|
+
activesupport (= 3.2.0.beta)
|
31
|
+
activesupport (3.2.0.beta)
|
32
|
+
i18n (~> 0.6)
|
33
|
+
multi_json (~> 1.0)
|
34
|
+
rails (3.2.0.beta)
|
35
|
+
actionmailer (= 3.2.0.beta)
|
36
|
+
actionpack (= 3.2.0.beta)
|
37
|
+
activerecord (= 3.2.0.beta)
|
38
|
+
activeresource (= 3.2.0.beta)
|
39
|
+
activesupport (= 3.2.0.beta)
|
40
|
+
bundler (~> 1.0)
|
41
|
+
railties (= 3.2.0.beta)
|
42
|
+
railties (3.2.0.beta)
|
43
|
+
actionpack (= 3.2.0.beta)
|
44
|
+
activesupport (= 3.2.0.beta)
|
45
|
+
rack-ssl (~> 1.3.2)
|
46
|
+
rake (>= 0.8.7)
|
47
|
+
rdoc (~> 3.4)
|
48
|
+
thor (~> 0.14.6)
|
49
|
+
|
50
|
+
PATH
|
51
|
+
remote: /home/cmeiklejohn/Repositories/seedable
|
52
|
+
specs:
|
53
|
+
seedable (0.0.1)
|
54
|
+
rails (>= 3.1.0)
|
55
|
+
|
56
|
+
GEM
|
57
|
+
remote: http://rubygems.org/
|
58
|
+
specs:
|
59
|
+
appraisal (0.3.8)
|
60
|
+
bundler
|
61
|
+
rake
|
62
|
+
arel (2.2.1)
|
63
|
+
builder (3.0.0)
|
64
|
+
diesel (0.1.5)
|
65
|
+
railties
|
66
|
+
diff-lcs (1.1.3)
|
67
|
+
erubis (2.7.0)
|
68
|
+
factory_girl (2.0.5)
|
69
|
+
factory_girl_rails (1.1.0)
|
70
|
+
factory_girl (~> 2.0.0)
|
71
|
+
railties (>= 3.0.0)
|
72
|
+
ffi (1.0.9)
|
73
|
+
guard (0.6.3)
|
74
|
+
thor (~> 0.14.6)
|
75
|
+
guard-rspec (0.4.3)
|
76
|
+
guard (>= 0.4.0)
|
77
|
+
hike (1.2.1)
|
78
|
+
horo (1.0.3)
|
79
|
+
rdoc (>= 2.5)
|
80
|
+
i18n (0.6.0)
|
81
|
+
libnotify (0.5.7)
|
82
|
+
mail (2.3.0)
|
83
|
+
i18n (>= 0.4.0)
|
84
|
+
mime-types (~> 1.16)
|
85
|
+
treetop (~> 1.4.8)
|
86
|
+
mime-types (1.16)
|
87
|
+
mocha (0.9.12)
|
88
|
+
multi_json (1.0.3)
|
89
|
+
polyglot (0.3.2)
|
90
|
+
rack (1.3.2)
|
91
|
+
rack-cache (1.0.3)
|
92
|
+
rack (>= 0.4)
|
93
|
+
rack-mount (0.8.3)
|
94
|
+
rack (>= 1.0.0)
|
95
|
+
rack-ssl (1.3.2)
|
96
|
+
rack
|
97
|
+
rack-test (0.6.1)
|
98
|
+
rack (>= 1.0)
|
99
|
+
rake (0.9.2)
|
100
|
+
rb-inotify (0.8.6)
|
101
|
+
ffi (>= 0.5.0)
|
102
|
+
rdoc (3.9.4)
|
103
|
+
rspec (2.6.0)
|
104
|
+
rspec-core (~> 2.6.0)
|
105
|
+
rspec-expectations (~> 2.6.0)
|
106
|
+
rspec-mocks (~> 2.6.0)
|
107
|
+
rspec-core (2.6.4)
|
108
|
+
rspec-expectations (2.6.0)
|
109
|
+
diff-lcs (~> 1.1.2)
|
110
|
+
rspec-mocks (2.6.0)
|
111
|
+
rspec-rails (2.6.1)
|
112
|
+
actionpack (~> 3.0)
|
113
|
+
activesupport (~> 3.0)
|
114
|
+
railties (~> 3.0)
|
115
|
+
rspec (~> 2.6.0)
|
116
|
+
simplecov (0.4.2)
|
117
|
+
simplecov-html (~> 0.4.4)
|
118
|
+
simplecov-html (0.4.5)
|
119
|
+
sprockets (2.0.0)
|
120
|
+
hike (~> 1.2)
|
121
|
+
rack (~> 1.0)
|
122
|
+
tilt (!= 1.3.0, ~> 1.1)
|
123
|
+
sqlite3 (1.3.4)
|
124
|
+
thor (0.14.6)
|
125
|
+
tilt (1.3.3)
|
126
|
+
timecop (0.3.5)
|
127
|
+
treetop (1.4.10)
|
128
|
+
polyglot
|
129
|
+
polyglot (>= 0.3.1)
|
130
|
+
tzinfo (0.3.29)
|
131
|
+
|
132
|
+
PLATFORMS
|
133
|
+
ruby
|
134
|
+
|
135
|
+
DEPENDENCIES
|
136
|
+
appraisal (~> 0.3.5)
|
137
|
+
bundler (~> 1.0.0)
|
138
|
+
diesel
|
139
|
+
factory_girl
|
140
|
+
factory_girl_rails
|
141
|
+
guard
|
142
|
+
guard-rspec
|
143
|
+
horo
|
144
|
+
libnotify
|
145
|
+
mocha
|
146
|
+
rails!
|
147
|
+
rb-inotify
|
148
|
+
rspec
|
149
|
+
rspec-rails
|
150
|
+
seedable!
|
151
|
+
simplecov
|
152
|
+
sqlite3
|
153
|
+
timecop
|