traver 0.3.4.1 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -1
- data/lib/traver/object_creator.rb +8 -1
- data/lib/traver/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d8da9e9570bf567dc1b8142b210e8ba7d5c71ae
|
4
|
+
data.tar.gz: 16c26550bb9b5452eda1754ca17d53c134c9544c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a2b19e5f3bdcd5ee41d8b5e3d5d0b5c3c1f2ac26e60c5c8268c8ac73100beb357e88c169b05ad49dbc73fe4bf943b36f2b27663bf35be8de12868916904f81f
|
7
|
+
data.tar.gz: 39cffdcd0bcd2400f724002875a6febe078bf1afd2821dcae4708a08b93347e4d3f0f8e4155c51a88a58083b57bbe92e2fe8a7437d5948ef11b60e242d7eb93c
|
data/README.md
CHANGED
@@ -143,6 +143,29 @@ Create associated with already existing objects:
|
|
143
143
|
Traver.create(blog: { title: "Hello", posts: [post1, post2] })
|
144
144
|
```
|
145
145
|
|
146
|
+
### Reusing associations
|
147
|
+
|
148
|
+
Traver reuses already created objects for similar associations:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
class Blog
|
152
|
+
belongs_to :user
|
153
|
+
has_many :posts
|
154
|
+
end
|
155
|
+
|
156
|
+
class Post
|
157
|
+
belongs_to :user
|
158
|
+
end
|
159
|
+
```
|
160
|
+
```ruby
|
161
|
+
blog = Traver.create(blog, posts: 1) # => blog.user == blog.posts.first.user
|
162
|
+
```
|
163
|
+
|
164
|
+
We can explicitly specify to create separate users for blog and a post:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
blog = Traver.create(blog, posts: [ { user: 1 } ]) # => blog.user != blog.posts.first.user
|
168
|
+
```
|
146
169
|
|
147
170
|
Create lists with sequences:
|
148
171
|
|
@@ -186,7 +209,7 @@ Use procs for dynamic attribute values:
|
|
186
209
|
```ruby
|
187
210
|
blog = Traver.create(event: {
|
188
211
|
start_at: -> { 1.day.ago },
|
189
|
-
finish_at: -> { start_at + 2.days }
|
212
|
+
finish_at: -> (object) { object.start_at + 2.days }
|
190
213
|
})
|
191
214
|
```
|
192
215
|
|
@@ -92,7 +92,14 @@ module Traver
|
|
92
92
|
|
93
93
|
def set_attribute(attribute, value)
|
94
94
|
if value.is_a?(Proc)
|
95
|
-
value =
|
95
|
+
value =
|
96
|
+
if value.arity == 0
|
97
|
+
value.call
|
98
|
+
elsif value.arity == 1
|
99
|
+
value.call(object)
|
100
|
+
else
|
101
|
+
raise "Parameter block can have either 0 or 1 argument"
|
102
|
+
end
|
96
103
|
elsif value.is_a?(String)
|
97
104
|
if sequencer.value_has_sequence?(value)
|
98
105
|
value = sequencer.interpolate_sequence(attribute, value)
|
data/lib/traver/version.rb
CHANGED