pickle-dupe 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/features/app/dupe_definitions.rb +4 -0
- data/lib/pickle_dupe/adapter.rb +9 -12
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/pickle_dupe/adapter.rb
CHANGED
@@ -17,12 +17,17 @@ module Pickle
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize(model)
|
20
|
-
|
20
|
+
# Not all dupe models has an associated model class
|
21
|
+
# so we dynamically create them here
|
22
|
+
unless @klass = (model.name.to_s.classify.constantize rescue nil)
|
23
|
+
Object.const_set(model.name.to_s.classify, Class.new(ActiveResource::Base))
|
24
|
+
end
|
25
|
+
@name = model.name.to_s
|
21
26
|
end
|
22
27
|
|
23
28
|
def create(attrs = {})
|
24
29
|
duped_object = ::Dupe.create(@name, attrs)
|
25
|
-
assign_missing_associations(duped_object, attrs) unless attrs.blank?
|
30
|
+
assign_missing_associations (duped_object, attrs) unless attrs.blank?
|
26
31
|
|
27
32
|
return duped_object
|
28
33
|
end
|
@@ -74,21 +79,13 @@ module Pickle
|
|
74
79
|
def assign_missing_associations(duped_object, attrs)
|
75
80
|
association_objects = collect_association_objects(attrs)
|
76
81
|
association_objects.each {|association_object|
|
77
|
-
|
78
82
|
# When a pickle step causes Dupe to do the following:
|
79
83
|
#
|
80
84
|
# Dupe.create(:direction_step, :recipe => @recipe)
|
81
85
|
#
|
82
86
|
# Then duped_object would be of class Dupe::DirectionStep and association_object would be of
|
83
87
|
# class Dupe::Recipe.
|
84
|
-
|
85
|
-
if association_object.kind_of?(Array)
|
86
|
-
association_object.each {|a|
|
87
|
-
assign_association(a, duped_object)
|
88
|
-
}
|
89
|
-
else
|
90
|
-
assign_association(association_object, duped_object)
|
91
|
-
end
|
88
|
+
assign_association(association_object, duped_object)
|
92
89
|
}
|
93
90
|
end
|
94
91
|
|
@@ -112,7 +109,7 @@ module Pickle
|
|
112
109
|
def collect_association_objects(attrs)
|
113
110
|
attrs.select {|k,v|
|
114
111
|
v.kind_of?(Array) || v.kind_of?(::Dupe::Database::Record)
|
115
|
-
}.collect {|i| i[1]}
|
112
|
+
}.collect {|i| i[1]}.flatten
|
116
113
|
end
|
117
114
|
|
118
115
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- iawgens
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-02 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|