mad_id 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mad_id.rb +6 -0
- data/lib/mad_id/railtie.rb +0 -1
- data/lib/mad_id/version.rb +1 -1
- data/spec/mad_id_spec.rb +19 -0
- 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: 640ca4a57c32063613b126cac922b1d6d88f1c17
|
4
|
+
data.tar.gz: a1f46a5dc25dbba7793fe31ea1616225aa46ac9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2f080018fe1954dcdd9c19ac7321693f35ae3fe5b1042c49c498f56f3a5b7df41d020751fbf6fee5a1589c31e6823303260376e78f4cbfedea52d5a501ec152
|
7
|
+
data.tar.gz: e77b9a62c91a27408593ac116be6b7b30e7f445e56220c91f672b313b34e839a5c728dd53ae86896bc33e929ff049b2acbe3599e154c1ce669fd634c4873f2e1
|
data/lib/mad_id.rb
CHANGED
@@ -13,6 +13,11 @@ module MadID
|
|
13
13
|
@registry = {}
|
14
14
|
class << self
|
15
15
|
attr_accessor :registry
|
16
|
+
|
17
|
+
def locate(id)
|
18
|
+
prefix, _ = id.split('-', 2)
|
19
|
+
registry[prefix].find_by_mad_id!(id)
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
included do
|
@@ -20,6 +25,7 @@ module MadID
|
|
20
25
|
@identifier = value
|
21
26
|
MadID.registry[value.to_s] = self
|
22
27
|
self.send(:include, MadID::IdentityMethods)
|
28
|
+
self.extend(MadID::FinderMethods)
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
data/lib/mad_id/railtie.rb
CHANGED
data/lib/mad_id/version.rb
CHANGED
data/spec/mad_id_spec.rb
CHANGED
@@ -8,6 +8,10 @@ class LittlePony < Pony
|
|
8
8
|
identify_with :pny
|
9
9
|
end
|
10
10
|
|
11
|
+
class GreatPony < Pony
|
12
|
+
identify_with :grtpny
|
13
|
+
end
|
14
|
+
|
11
15
|
describe MadID do
|
12
16
|
|
13
17
|
it 'inserts #identify_with' do
|
@@ -72,4 +76,19 @@ describe MadID do
|
|
72
76
|
expect(MadID.registry).to include('pny' => LittlePony)
|
73
77
|
end
|
74
78
|
end
|
79
|
+
|
80
|
+
describe 'Locator' do
|
81
|
+
let!(:little_pony) { LittlePony.create }
|
82
|
+
let!(:great_pony) { GreatPony.create }
|
83
|
+
|
84
|
+
it 'locate the little pony just by the identifier' do
|
85
|
+
expect(MadID.locate(little_pony.identifier)).to eq(little_pony)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'locate the great pony just by the identifier' do
|
89
|
+
binding
|
90
|
+
expect(MadID.locate(great_pony.identifier)).to eq(great_pony)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
75
94
|
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: 0.3.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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|