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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd87dedc042e4ebeabd5c1072b599e075e1d8cf4
4
- data.tar.gz: e8ce071f04b60dc6c7717392adb98367cc813d6c
3
+ metadata.gz: 6d8da9e9570bf567dc1b8142b210e8ba7d5c71ae
4
+ data.tar.gz: 16c26550bb9b5452eda1754ca17d53c134c9544c
5
5
  SHA512:
6
- metadata.gz: 69693dd9c6dad7191b9bc7964192fa8c0a3df3c10b9bbbba372ada6325f5597f29d84c70d4df868762ec9dc989f6603634a2fd1db3114768cb0e677a5f4fab4c
7
- data.tar.gz: ff59457a33ebca11e9af09e490ddab71c0ec194b4aeb1719b05851f5db1f60c124225c739334f11c579455e7aebfe9b5acbd9f6faa340fd9879f44eba56e2649
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 = object.instance_exec(&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)
@@ -1,3 +1,3 @@
1
1
  module Traver
2
- VERSION = "0.3.4.1"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4.1
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Kaspervich