seedlings 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/seedlings.rb +3 -3
- data/lib/seedlings/version.rb +1 -1
- data/spec/README.md +1 -1
- data/spec/lib/seedlings_spec.rb +3 -3
- metadata +2 -4
- data/spec/connections/test.sqlite3 +0 -0
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -15,7 +15,7 @@ There are two methods of note: `.plant` and `.plant_and_return`. They take 3 par
|
|
15
15
|
* the Class to use (must support `ActiveModel`ish interface, like MongoMapper, Mongoid, ActiveRecord)
|
16
16
|
* options you want Seedlings to respect, of which there are two:
|
17
17
|
* `:constrain` which takes a column name or array of column names that will be used to find the records, and
|
18
|
-
* `:
|
18
|
+
* `:update_existing`, which, if set to false, will cause Seedlings to skip updating existing records. **By default Seedlings always updates.**
|
19
19
|
* the third parameter is that data you want seeded. `.plant` takes however many attribute hashes you give it. `.plant_and_return` takes only a single hash, but returns the resulting object.
|
20
20
|
|
21
21
|
Here's some examples:
|
data/lib/seedlings.rb
CHANGED
@@ -18,7 +18,7 @@ class Seedlings
|
|
18
18
|
|
19
19
|
def initialize klass, options, data
|
20
20
|
self.klass = klass
|
21
|
-
self.options = options
|
21
|
+
self.options = { :update_existing => true }.merge(options)
|
22
22
|
self.data = data
|
23
23
|
adapt!
|
24
24
|
end
|
@@ -70,8 +70,8 @@ class Seedlings
|
|
70
70
|
object = find_model_with the_data
|
71
71
|
if object
|
72
72
|
puts "FOUND: #{object.inspect}"
|
73
|
-
if options[:
|
74
|
-
puts " * skipping update as per options[:
|
73
|
+
if !options[:update_existing]
|
74
|
+
puts " * skipping update as per options[:update_existing]"
|
75
75
|
else
|
76
76
|
puts " * updating with #{the_data}"
|
77
77
|
object.update_attributes(the_data)
|
data/lib/seedlings/version.rb
CHANGED
data/spec/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
## Running Specs
|
2
2
|
|
3
|
-
By default, we run the specs with mongomapper. To run them with mongoid or sqlite, use: `DB=mongoid rspec spec
|
3
|
+
By default, we run the specs with mongomapper. To run them with mongoid or sqlite, use: `DB=mongoid rspec spec` or `DB=sqlite rspec spec`. SQLite is super easy and should require 0 setup. #winning!
|
4
4
|
|
5
5
|
Taking our cues from seed-fu, I've placed the connection and model setup stuff out in `spec/connections/*`.
|
data/spec/lib/seedlings_spec.rb
CHANGED
@@ -41,7 +41,7 @@ describe Seedlings do
|
|
41
41
|
describe "#initialize" do
|
42
42
|
it "stashes the class, options, and data as attributes" do
|
43
43
|
seeds.klass.should == Widget
|
44
|
-
seeds.options.should == { :constrain => :name }
|
44
|
+
seeds.options.should == { :constrain => :name, :update_existing => true }
|
45
45
|
seeds.data.should == []
|
46
46
|
end
|
47
47
|
end
|
@@ -129,8 +129,8 @@ describe Seedlings::ActiveModel do
|
|
129
129
|
seedlings.find_and_update_model_with the_attrs
|
130
130
|
Widget.where(name: "Basic text elements").first.context.should == "hero"
|
131
131
|
end
|
132
|
-
it "skips the update if you've
|
133
|
-
seeds = Seedlings.new(Widget, { :constrain => :name, :
|
132
|
+
it "skips the update if you've set :update_existing to false" do
|
133
|
+
seeds = Seedlings.new(Widget, { :constrain => :name, :update_existing => false }, the_attrs )
|
134
134
|
seeds.find_and_update_model_with the_attrs
|
135
135
|
Widget.where(name: "Basic text elements").first.context.should == "columns"
|
136
136
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: seedlings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Matt Wilson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -102,7 +102,6 @@ files:
|
|
102
102
|
- spec/connections/mongoid.rb
|
103
103
|
- spec/connections/mongomapper.rb
|
104
104
|
- spec/connections/sqlite.rb
|
105
|
-
- spec/connections/test.sqlite3
|
106
105
|
- spec/lib/seedlings_spec.rb
|
107
106
|
- spec/spec_helper.rb
|
108
107
|
homepage: ""
|
@@ -137,6 +136,5 @@ test_files:
|
|
137
136
|
- spec/connections/mongoid.rb
|
138
137
|
- spec/connections/mongomapper.rb
|
139
138
|
- spec/connections/sqlite.rb
|
140
|
-
- spec/connections/test.sqlite3
|
141
139
|
- spec/lib/seedlings_spec.rb
|
142
140
|
- spec/spec_helper.rb
|
Binary file
|