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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 316bc10f1801f7f68016bca9bc097d9c26ebbca4
4
- data.tar.gz: 1a127701a912eb9c26f49a75fe96aefefee7df83
3
+ metadata.gz: 640ca4a57c32063613b126cac922b1d6d88f1c17
4
+ data.tar.gz: a1f46a5dc25dbba7793fe31ea1616225aa46ac9e
5
5
  SHA512:
6
- metadata.gz: 235c69abe9a22cb8dc20d4a6b9b99dd075c6a299f0726463b65512f588c8925abc933807c70f302d478f2b2f285661aa59024528376e33728c579b66c9fb1502
7
- data.tar.gz: 790415281b773ea475013e5f51289cc215e28d8971616f0e2527f9b19879efe5ad77a24fd1220d447e7c9e020f616b901386e01ec49196fd35dad0f961ff1584
6
+ metadata.gz: b2f080018fe1954dcdd9c19ac7321693f35ae3fe5b1042c49c498f56f3a5b7df41d020751fbf6fee5a1589c31e6823303260376e78f4cbfedea52d5a501ec152
7
+ data.tar.gz: e77b9a62c91a27408593ac116be6b7b30e7f445e56220c91f672b313b34e839a5c728dd53ae86896bc33e929ff049b2acbe3599e154c1ce669fd634c4873f2e1
@@ -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
@@ -3,7 +3,6 @@ module MadID
3
3
  initializer 'mad_id.initialize' do |app|
4
4
  ActiveSupport.on_load :active_record do
5
5
  ActiveRecord::Base.send(:include, MadID)
6
- ActiveRecord::Base.extend( MadID::FinderMethods)
7
6
  end
8
7
  end
9
8
  end
@@ -1,3 +1,3 @@
1
1
  module MadID
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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.2.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-13 00:00:00.000000000 Z
11
+ date: 2014-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord