passive_record 0.4.2 → 0.4.3

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: bd7a8be879b1a85836a8b2cb0267bbbeb1c7d4b6
4
- data.tar.gz: 3d4255fe38bcc4215191a64dd0ed7ab0d3da2177
3
+ metadata.gz: 40a7223415652b0909737104ce89ef4b217ea868
4
+ data.tar.gz: 6c12988254b55576d5233dc5342efb57885d980d
5
5
  SHA512:
6
- metadata.gz: 5d66d816841d803ad686444e9be0e92eca84c3b4edd16f8ab48afc85240b7f5cc6e29afa6f1d1f0b690560974acf3b97d297af3620e32b8e8d5521d12453017c
7
- data.tar.gz: 39f2ebeef81f00a4e194fe67ee3f0914f36570d836cfb2e68beb0e37cdf5d2ce97280f0b2e8c31ed9ed5325701bdbcc168fb106cbfc7156fdfff4127c632bf57
6
+ metadata.gz: a7ace663d5d19795a44d2db854dbfb1d927d5f17b3f846efe2d7c8e6d360a99339f83045a12c041cadb85426fd3166230b08218dbb84a309d58047780bf1c202
7
+ data.tar.gz: 472bc65c4d271b5ee23913163734f1434b45948e7f78331dd55a33c2994cb16449c421bd32c5e1ce42ee42e2d256f1fe04affa8d64e139e95ced64ab578e1253
data/README.md CHANGED
@@ -106,15 +106,15 @@ PassiveRecord may be right for you!
106
106
  A class `User` which is declared to `include PassiveRecord` will gain the following class methods:
107
107
 
108
108
  - `User.all` and `User.each`
109
- - `User.create(attrs_hash)`
109
+ - `User.create(name: 'Aloysius')`
110
110
  - `User.descendants`
111
111
  - `User.destroy(id)`
112
112
  - `User.destroy_all`
113
113
  - `User.each` enumerates over `User.all`, giving `User.count`, `User.first`, etc.
114
114
  - `User.find(id_or_ids)`
115
- - `User.find_all_by(conditions_hash)`
116
- - `User.find_by(conditions_hash)`
117
- - `User.where(conditions_hash)` (returns a `PassiveRecord::Query` object)
115
+ - `User.find_by(name: 'Aloysius')`
116
+ - `User.find_all_by(job: ['manager', 'developer', 'qa'])`
117
+ - `User.where(birthday: 1.day.ago...1.day.from_now)` (returns a `PassiveRecord::Query` object)
118
118
 
119
119
  ### Belongs To
120
120
 
@@ -183,9 +183,9 @@ PassiveRecord may be right for you!
183
183
 
184
184
  `conditions` here is expected to be a hash of attribute values. Note that there is special behavior for certain kinds of values.
185
185
 
186
- - Ranges select models with an attribute covered by the range (behaving like `BETWEEN`)
187
- - Arrays select models with an attribute whose value is in the array (behaving like `IN`)
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`.
186
+ - Ranges select models with an attribute covered by the range (behaving like `BETWEEN`). For instance you might query for users with birthdays between yesterday and today with `User.where(birthday: 1.day.ago...1.day.from_now)`
187
+ - Arrays select models with an attribute whose value is in the array (behaving like `IN`), so for instance you may query for users whose job title is included in a list of job titles like: `User.find_all_by(job_title: ['manager', 'developer', 'qa'])`
188
+ - Hash values (subhashes) select models with related models who attributes match the inner hash. So `Doctor.where(appointments: { patient: patient })` would lookup doctors whose appointments include an appointment with `patient`.
189
189
 
190
190
  ## Hooks
191
191
 
@@ -198,18 +198,8 @@ PassiveRecord may be right for you!
198
198
 
199
199
  # Prior Art
200
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, similar to
204
- 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. However
208
- I don't really see a way to do relations that interoperate with ActiveRecord the way you could, at least to some degree, with tableless models.
209
- - It's not really clear to me yet if it's interesting for PassiveRecord to be able to interoperate smoothly with ActiveRecord relations. It
210
- seems like we might be able to pull some similar tricks as the "tableless" approach in order to permit at least some relations to work between them.
211
- But their intentions are so different I can't help but think there would be very strange bugs lurking in any such integration -- so the encouraged
212
- architecture would be a complete separation between active and passive models.
201
+ - Approaches exist that use ActiveRecord directly, and then override various methods in such a way to prevent AR from trying to persist the model. The canonical example here is the [tableless model](http://railscasts.com/episodes/193-tableless-model?view=asciicast) approach, and the use case given there is a model that wraps around sending an email. This is maybe interesting because, similar to the round-trip with a database, sending mail is externally "effectful" (and so, for instance, you may wish to take additional care around confirmation or retry logic, in order ensure you are not sending the same message more than once.)
202
+ - These approaches are seen as somewhat hacky today, given that [ActiveModel](https://github.com/rails/rails/tree/master/activemodel) can give plain old Ruby objects a lot of the augmentations that ActiveRecord gives, such as validations, hooks and attribute management. However I don't really see a way to do relations that interoperate with ActiveRecord the way you could, at least to some degree, with tableless models. - It's not really clear to me yet if it's interesting for PassiveRecord to be able to interoperate smoothly with ActiveRecord relations. It seems like we might be able to pull some similar tricks as the "tableless" approach in order to permit at least some relations to work between them. But their intentions are so different I can't help but think there would be very strange bugs lurking in any such integration -- so the encouraged architecture would be a complete separation between active and passive models.
213
203
 
214
204
  ## Copyright
215
205
 
@@ -72,7 +72,6 @@ module PassiveRecord
72
72
 
73
73
  define_method(:"#{child_name_sym}_id=") do |new_child_id|
74
74
  relation = relata.detect { |rel| rel.association == association }
75
- # detach existing child...
76
75
  rel = relation.lookup
77
76
  rel && rel.send(:"#{relation.parent_model_id_field}=", nil)
78
77
 
@@ -6,7 +6,6 @@ module PassiveRecord
6
6
  end
7
7
 
8
8
  def parent_class
9
- # look in same namespace as child class
10
9
  module_name = child_class.name.deconstantize
11
10
  module_name = "Object" if module_name.empty?
12
11
  (module_name.constantize).const_get(parent_class_name)
@@ -38,11 +38,9 @@ module PassiveRecord
38
38
  end
39
39
 
40
40
  def child_class
41
- # look in same module as parent...
42
41
  module_name = association.parent_class.name.deconstantize
43
42
  module_name = "Object" if module_name.empty?
44
- (module_name.constantize).
45
- const_get(association.child_class_name.singularize)
43
+ (module_name.constantize).const_get(association.child_class_name.singularize)
46
44
  end
47
45
 
48
46
  def id
@@ -34,11 +34,7 @@ module PassiveRecord
34
34
  end
35
35
 
36
36
  def find_all_by(conditions)
37
- if conditions.is_a?(Array) && conditions.all? { |c| c.is_a?(Identifier) }
38
- find_by_ids(conditions)
39
- else
40
- where(conditions).all
41
- end
37
+ where(conditions).all
42
38
  end
43
39
 
44
40
  def where(conditions={})
@@ -84,7 +80,7 @@ module PassiveRecord
84
80
  end
85
81
 
86
82
  def find_by_ids(ids)
87
- instances_by_id.select { |id,_| ids.include?(id) }.values
83
+ instances_by_id.values_at(*ids)
88
84
  end
89
85
 
90
86
  private
@@ -1,4 +1,4 @@
1
1
  module PassiveRecord
2
2
  # passive_record version
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  end
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.4.2
4
+ version: 0.4.3
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-26 00:00:00.000000000 Z
11
+ date: 2016-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport