mad_id 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/mad_id.rb +11 -2
- data/lib/mad_id/finder_methods.rb +3 -0
- data/lib/mad_id/version.rb +1 -1
- data/spec/mad_id_spec.rb +23 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a27c381fd81182c7d63f410bafe22881658ef18
|
4
|
+
data.tar.gz: ee2e7893a7c1d0b4a93a090af0564a9c59ef265d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c50472189f0a2f807b365b3c1be2fc44bfad11776a376a60f20d42c9ccd27b4e255dd50aedde2b17c232b0a3c19d3f28d1ae1635bc94b774bfa9925533b0028
|
7
|
+
data.tar.gz: eac2d8d39d5aab593d45150ad8d85ee8970d7d626948ec7fae7403c5a244d6cefd13fcc54580c0f186ea9ac3baa8d9d0530cd17a3bcc137ac91361b7ffc6d51a
|
data/README.md
CHANGED
@@ -53,6 +53,11 @@ You can access all registered identifiers and the associated class via MadID's r
|
|
53
53
|
MadID.registry
|
54
54
|
# => { 'foo' => YourModel }
|
55
55
|
|
56
|
+
### Locator
|
57
|
+
|
58
|
+
MadID.locate("pny-1312313412")
|
59
|
+
# => #Object:Pony:1312313412
|
60
|
+
|
56
61
|
## Contributing
|
57
62
|
|
58
63
|
1. Fork it ( http://github.com/<my-github-username>/mad_id/fork )
|
data/lib/mad_id.rb
CHANGED
@@ -15,8 +15,17 @@ module MadID
|
|
15
15
|
attr_accessor :registry
|
16
16
|
|
17
17
|
def locate(id)
|
18
|
-
prefix, _ = id.split('-', 2)
|
19
|
-
registry[prefix]
|
18
|
+
prefix, _ = id.to_s.split('-', 2)
|
19
|
+
if klass = registry[prefix]
|
20
|
+
klass.find_by_mad_id(id)
|
21
|
+
else
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def locate!(id)
|
27
|
+
prefix, _ = id.to_s.split('-', 2)
|
28
|
+
registry.fetch(prefix).find_by_mad_id!(id)
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
data/lib/mad_id/version.rb
CHANGED
data/spec/mad_id_spec.rb
CHANGED
@@ -81,14 +81,31 @@ describe MadID do
|
|
81
81
|
let!(:little_pony) { LittlePony.create }
|
82
82
|
let!(:great_pony) { GreatPony.create }
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
describe 'locate' do
|
85
|
+
it 'locate the little pony just by the identifier' do
|
86
|
+
expect(MadID.locate(little_pony.identifier)).to eq(little_pony)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'locate the great pony just by the identifier' do
|
90
|
+
expect(MadID.locate(great_pony.identifier)).to eq(great_pony)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns nil if no klass is found for the identifier' do
|
94
|
+
expect(MadID.locate("noo-getting-cold")).to be_nil
|
95
|
+
end
|
87
96
|
|
88
|
-
|
89
|
-
|
90
|
-
|
97
|
+
it 'returns nil if nothing is found' do
|
98
|
+
expect(MadID.locate("pny-no-pony-there")).to be_nil
|
99
|
+
end
|
91
100
|
end
|
101
|
+
describe 'locate!' do
|
102
|
+
it 'raises an error if no class is found' do
|
103
|
+
expect { MadID.locate!("noo-class-there") }.to raise_error(KeyError)
|
104
|
+
end
|
92
105
|
|
106
|
+
it 'raises an error if no record is found' do
|
107
|
+
expect { MadID.locate!("pny-class-there") }.to raise_error(ActiveRecord::RecordNotFound)
|
108
|
+
end
|
109
|
+
end
|
93
110
|
end
|
94
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mad_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Brillert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|