passive_record 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/passive_record.rb +0 -1
- data/lib/passive_record/class_methods.rb +5 -12
- data/lib/passive_record/version.rb +1 -1
- data/spec/passive_record_spec.rb +2 -5
- metadata +2 -3
- data/lib/passive_record/core/identifier.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd7a8be879b1a85836a8b2cb0267bbbeb1c7d4b6
|
4
|
+
data.tar.gz: 3d4255fe38bcc4215191a64dd0ed7ab0d3da2177
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d66d816841d803ad686444e9be0e92eca84c3b4edd16f8ab48afc85240b7f5cc6e29afa6f1d1f0b690560974acf3b97d297af3620e32b8e8d5521d12453017c
|
7
|
+
data.tar.gz: 39f2ebeef81f00a4e194fe67ee3f0914f36570d836cfb2e68beb0e37cdf5d2ce97280f0b2e8c31ed9ed5325701bdbcc168fb106cbfc7156fdfff4127c632bf57
|
data/lib/passive_record.rb
CHANGED
@@ -5,7 +5,6 @@ require 'active_support/core_ext/string/inflections'
|
|
5
5
|
require 'active_support/core_ext/numeric/time'
|
6
6
|
|
7
7
|
require 'passive_record/version'
|
8
|
-
require 'passive_record/core/identifier'
|
9
8
|
|
10
9
|
require 'passive_record/arithmetic_helpers'
|
11
10
|
require 'passive_record/core/query'
|
@@ -15,11 +15,7 @@ module PassiveRecord
|
|
15
15
|
def all
|
16
16
|
instances_by_id.values
|
17
17
|
end
|
18
|
-
def_delegators :all, :each
|
19
|
-
|
20
|
-
def last
|
21
|
-
all.last
|
22
|
-
end
|
18
|
+
def_delegators :all, :each, :last
|
23
19
|
|
24
20
|
def find(id_or_ids)
|
25
21
|
if id_or_ids.is_a?(Array)
|
@@ -54,7 +50,7 @@ module PassiveRecord
|
|
54
50
|
|
55
51
|
instance.singleton_class.class_eval { attr_accessor :id }
|
56
52
|
|
57
|
-
instance_id = attrs.delete(:id) {
|
53
|
+
instance_id = attrs.delete(:id) { SecureRandom.uuid }
|
58
54
|
instance.send(:id=, instance_id)
|
59
55
|
|
60
56
|
register(instance)
|
@@ -84,7 +80,7 @@ module PassiveRecord
|
|
84
80
|
|
85
81
|
protected
|
86
82
|
def find_by_id(id_to_find)
|
87
|
-
|
83
|
+
instances_by_id[id_to_find]
|
88
84
|
end
|
89
85
|
|
90
86
|
def find_by_ids(ids)
|
@@ -97,12 +93,9 @@ module PassiveRecord
|
|
97
93
|
end
|
98
94
|
|
99
95
|
def register(model)
|
100
|
-
|
96
|
+
id = model.id
|
97
|
+
instances_by_id[id] = model
|
101
98
|
self
|
102
99
|
end
|
103
|
-
|
104
|
-
def id_factory
|
105
|
-
PassiveRecord.configuration.identify_using
|
106
|
-
end
|
107
100
|
end
|
108
101
|
end
|
data/spec/passive_record_spec.rb
CHANGED
@@ -112,14 +112,11 @@ describe "passive record models" do
|
|
112
112
|
|
113
113
|
context 'querying by id' do
|
114
114
|
describe "#find" do
|
115
|
-
subject(:model) {
|
115
|
+
subject(:model) { SimpleModel.create(id: 'model_id') }
|
116
116
|
it 'should lookup a record based on an identifier' do
|
117
117
|
expect(SimpleModel.find(-1)).to eq(nil)
|
118
118
|
expect(SimpleModel.find(model.id)).to eq(model)
|
119
|
-
|
120
|
-
|
121
|
-
it 'should lookup records based on primary key value' do
|
122
|
-
expect(SimpleModel.find(model.id.value)).to eq(model)
|
119
|
+
expect(SimpleModel.find('model_id')).to eq(model)
|
123
120
|
end
|
124
121
|
|
125
122
|
it 'should lookup records based on ids' do
|
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.
|
4
|
+
version: 0.4.2
|
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-
|
11
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -156,7 +156,6 @@ files:
|
|
156
156
|
- lib/passive_record/associations/has_one.rb
|
157
157
|
- lib/passive_record/class_inheritable_attrs.rb
|
158
158
|
- lib/passive_record/class_methods.rb
|
159
|
-
- lib/passive_record/core/identifier.rb
|
160
159
|
- lib/passive_record/core/query.rb
|
161
160
|
- lib/passive_record/hooks.rb
|
162
161
|
- lib/passive_record/instance_methods.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module PassiveRecord
|
2
|
-
class SecureRandomIdentifier < Struct.new(:value)
|
3
|
-
def self.generate(klass)
|
4
|
-
new(generate_id_value_for(klass))
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.generate_id_value_for(*)
|
8
|
-
SecureRandom.uuid
|
9
|
-
end
|
10
|
-
|
11
|
-
def ==(other_id)
|
12
|
-
self.value == other_id ||
|
13
|
-
(other_id.is_a?(SecureRandomIdentifier) && (other_id && self.value == other_id.value))
|
14
|
-
end
|
15
|
-
|
16
|
-
def inspect
|
17
|
-
value
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|