passive_record 0.3.20 → 0.3.21

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: fe98ab7ab71c5ce3976bfc86076c2714714a164d
4
- data.tar.gz: b239a92752e046940fb7e92d962126bedce4ca94
3
+ metadata.gz: 05fe6abf84205214c0d3779a4613948ba45d0b38
4
+ data.tar.gz: 850a284c872673bfce97d9d3aae3f3d8ad53ff63
5
5
  SHA512:
6
- metadata.gz: 61ef80f5bbbfad3e139e6517feac7dc35b804e3c9571986da164e56013d9963b8c2dd103d7fa50ef2d758384b7bf31a882397619654d8626c3b173dfa9857fe9
7
- data.tar.gz: 8f8fc1772b617aee99cc921a3e6eaded1c5f2ebeeca11b34f48ff6b95479bcecab2cd6702fee06164627c8e575b06a20a37b984dc3acdfc0865bfeffbd0fd173
6
+ metadata.gz: a6922efd24b8495fa04c469d94e47649b34503d8269834f5b06e3dee723f23cb8f89574ed44dcd581f6ce4abdde33b98b52a00fa916af595b05f9ecb34745c0e
7
+ data.tar.gz: a17f8bf707a0f6f1bae9cc40fee9a9fb659b8bc7c829f585783ef38caa591b7f4d8029684a1f3afc4876499961bb76df2a7542af4c4a43d294c894e931c5c76f
data/README.md CHANGED
@@ -186,7 +186,6 @@ PassiveRecord may be right for you!
186
186
  - Ranges select models with an attribute covered by the range (behaving like `BETWEEN`)
187
187
  - Arrays select models with an attribute whose value is in the array (behaving like `IN`)
188
188
  - Hash values (subhashes) select models with related models who attributes match the inner hash. So `Doctor.where(appointments: { patient: patient })` finds doctors whose appointments include an appointment with `patient`.
189
-
190
189
 
191
190
  ## Hooks
192
191
 
@@ -197,6 +196,16 @@ PassiveRecord may be right for you!
197
196
  - `before_destroy :something`
198
197
  - `after_destroy { something_else }`
199
198
 
199
+ # Prior Art
200
+
201
+ - Approaches exist that use ActiveRecord directly, and then override various methods in such a way to prevent AR from
202
+ trying to persist the model. The canonical example here is the [tableless model](http://railscasts.com/episodes/193-tableless-model?view=asciicast)
203
+ approach, and the use case given there is a model that wraps around sending an email. This is maybe interesting because it's
204
+ like the round-trip with a database, sending mail is externally "effectful" (and so, for instance, you may wish to take additional
205
+ care around confirmation or retry logic, in order ensure you are not sending the same message more than once.)
206
+ - These approaches are seen as somewhat hacky today, given that [ActiveModel](https://github.com/rails/rails/tree/master/activemodel) can
207
+ give plain old Ruby objects a lot of the augmentations that ActiveRecord gives, such as validations, hooks and attribute management.
208
+
200
209
  ## Copyright
201
210
 
202
211
  Copyright (c) 2016 Joseph Weissman
@@ -31,7 +31,7 @@ module PassiveRecord
31
31
  end
32
32
 
33
33
  define_method(parent_name_sym) do
34
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
34
+ relation = relata.detect { |rel| rel.association == association }
35
35
  association.parent_class.find(relation.parent_model_id)
36
36
  end
37
37
 
@@ -40,7 +40,7 @@ module PassiveRecord
40
40
  end
41
41
 
42
42
  define_method(:"#{parent_name_sym}_id=") do |new_parent_id|
43
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
43
+ relation = relata.detect { |rel| rel.association == association }
44
44
  relation.parent_model_id = new_parent_id
45
45
  end
46
46
  end
@@ -55,12 +55,12 @@ module PassiveRecord
55
55
  end
56
56
 
57
57
  define_method(child_name_sym) do
58
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
58
+ relation = relata.detect { |rel| rel.association == association }
59
59
  relation.lookup
60
60
  end
61
61
 
62
62
  define_method(:"create_#{child_name_sym}") do |attrs={}|
63
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
63
+ relation = relata.detect { |rel| rel.association == association }
64
64
  relation.create(attrs)
65
65
  end
66
66
 
@@ -69,7 +69,7 @@ module PassiveRecord
69
69
  end
70
70
 
71
71
  define_method(:"#{child_name_sym}_id=") do |new_child_id|
72
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
72
+ relation = relata.detect { |rel| rel.association == association }
73
73
  # detach existing child...
74
74
  relation.lookup&.send(:"#{relation.parent_model_id_field}=", nil)
75
75
 
@@ -99,7 +99,7 @@ module PassiveRecord
99
99
  end
100
100
 
101
101
  define_method(:"#{collection_name_sym.to_s.singularize}_ids=") do |new_collection_ids|
102
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
102
+ relation = relata.detect { |rel| rel.association == association }
103
103
 
104
104
  intermediary = relation.intermediary_relation
105
105
 
@@ -129,7 +129,7 @@ module PassiveRecord
129
129
  associate!(association)
130
130
 
131
131
  define_method(:"#{collection_name_sym}=") do |new_collection|
132
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
132
+ relation = relata.detect { |rel| rel.association == association }
133
133
 
134
134
  # detach existing children...
135
135
  relation.all.each do |child|
@@ -143,14 +143,13 @@ module PassiveRecord
143
143
  end
144
144
 
145
145
  define_method(:"#{collection_name_sym.to_s.singularize}_ids=") do |new_collection_ids|
146
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
146
+ relation = relata.detect { |rel| rel.association == association }
147
147
  send(:"#{collection_name_sym}=", relation.child_class.find(new_collection_ids))
148
148
  end
149
149
  end
150
150
 
151
151
  define_method(collection_name_sym) do
152
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
153
- relation
152
+ relata.detect { |rel| rel.association == association }
154
153
  end
155
154
 
156
155
  define_method(:"#{collection_name_sym.to_s.singularize}_ids") do
@@ -158,8 +157,8 @@ module PassiveRecord
158
157
  end
159
158
 
160
159
  define_method(:"create_#{collection_name_sym.to_s.singularize}") do |attrs={}|
161
- relation = instance_eval{relata}.detect { |rel| rel.association == association }
162
- relation.create(attrs)
160
+ relation = relata.detect { |rel| rel.association == association }
161
+ relation.create(attrs)
163
162
  end
164
163
  end
165
164
 
@@ -1,4 +1,4 @@
1
1
  module PassiveRecord
2
2
  # passive_record version
3
- VERSION = "0.3.20"
3
+ VERSION = "0.3.21"
4
4
  end
@@ -65,7 +65,7 @@ describe "passive record models" do
65
65
  to eq("Family::Dog (id: #{dog.id.inspect}, breed: \"#{dog.breed}\", created_at: #{dog.created_at}, sound: \"bark\", child_id: #{child.id.inspect})")
66
66
 
67
67
  expect(child.inspect).
68
- to eq("Family::Child (id: #{child.id.inspect}, created_at: #{child.created_at}, name: \"Alice\", toy_id: nil, toy_quality_ids: [], dog_ids: [#{dog.id.inspect}], parent_id: nil, secret_club_ids: [])")
68
+ to eq("Family::Child (id: #{child.id.inspect}, created_at: #{child.created_at}, name: \"Alice\", parent_id: nil, toy_id: nil, toy_quality_ids: [], dog_ids: [#{dog.id.inspect}], secret_club_ids: [])")
69
69
  end
70
70
  end
71
71
 
data/spec/spec_helper.rb CHANGED
@@ -39,10 +39,10 @@ module Family
39
39
  end
40
40
 
41
41
  class Child < Model
42
+ belongs_to :parent
42
43
  has_one :toy
43
44
  has_many :toy_qualities, :through => :toy
44
45
  has_many :dogs
45
- belongs_to :parent
46
46
  has_and_belongs_to_many :secret_clubs
47
47
 
48
48
  attr_reader :name
@@ -62,7 +62,6 @@ module Family
62
62
  has_many :toys, :through => :children
63
63
  end
64
64
  end
65
- #include Family
66
65
 
67
66
  ###
68
67
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passive_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.20
4
+ version: 0.3.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport