model_id 0.0.1 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c932a7c5e539e0e99a37cdd3923255a69a147a2
4
- data.tar.gz: 75a705190a4ff44ebaeeead15f1889d46556886e
3
+ metadata.gz: 1bf11cfa0e155744b639dd5eaf6b218bfaa8555f
4
+ data.tar.gz: 3e0ece3f6216eff0f4dd0bda1b70bb2492c5734f
5
5
  SHA512:
6
- metadata.gz: 6af130420c80adaba5c255212d7f9999c2e0f3e793ff6d1531e5fd7e1eb6ed955525bba1aeb614780cde004bdd067702acac5541212fd812b4454f1f9c2162e8
7
- data.tar.gz: 9bef358e76b0670e24a7682279d4415e4d06d4063bb020be7363f11edd89c9a167bd689aac26ca0f9bbe98d19bfc9141019d629ddb82a4189e381896e7c6bbd9
6
+ metadata.gz: f3f29ffbff48feeb467c3dcd9a659780dab9520f335aa849a66269ac2ef340f365f1e02e1a742283a3917064c7fb132ef25a7954ddea786540072a3d40544dda
7
+ data.tar.gz: 19046a6b0979206d1781b5e46f740fbd1a5c9d03699429accd9edf4a1d50e5490a5135fe8c315977ce0f89f21a0b7348d761cda31a3ecacdd3e5835e10414896
data/README.md CHANGED
@@ -28,10 +28,17 @@ Now your model has #model_id:
28
28
 
29
29
  User.new.model_id
30
30
 
31
- And you cand find instances by id:
31
+ And you can find instances by id:
32
32
 
33
33
  user = User.new
34
- User.find_by_id(user.model_id)
34
+ User.find_by_id(user.model_id) # => user
35
+
36
+ After you don't need this instance anymore you can delete it from the index by #delete_model:
37
+
38
+ user = User.new
39
+ User.find_by_id(user.model_id) # => user
40
+ user.delete_model
41
+ User.find_by_id(user.model_id) # => nil
35
42
 
36
43
  ## Notes
37
44
 
data/lib/model_id/base.rb CHANGED
@@ -13,6 +13,10 @@ module ModelId
13
13
  self.class.model_id_instances[@model_id] = self
14
14
  end
15
15
 
16
+ def delete_model
17
+ self.class.model_id_instances.delete @model_id
18
+ end
19
+
16
20
  def self.included(base)
17
21
  base.class_eval do
18
22
  class << self
@@ -1,3 +1,3 @@
1
1
  module ModelId
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -44,4 +44,11 @@ describe ModelId::Base do
44
44
  expect(@class_with_id.find_by_id(first_instance.model_id)).to eql(first_instance)
45
45
  expect(@class_with_id.find_by_id(second_instance.model_id)).to eql(second_instance)
46
46
  end
47
+
48
+ it 'should delete model from index' do
49
+ instance = @class_with_id.new
50
+ expect(@class_with_id.find_by_id(instance.model_id)).to eql(instance)
51
+ instance.delete_model
52
+ expect(@class_with_id.find_by_id(instance.model_id)).to be_nil
53
+ end
47
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - abonec