ohm 2.0.0.alpha2 → 2.0.0.alpha3

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: 8294935327780b3b34f3e4ab6f84b59332d0037b
4
- data.tar.gz: 9159ad5202c945da06f36b3e8e0cdc49472d928b
3
+ metadata.gz: b3734bd99776bff0786c42047b43dbeed799d907
4
+ data.tar.gz: f3883cf4aa7fea58b716b5e5dd0796458bfda388
5
5
  SHA512:
6
- metadata.gz: 84a62af64f0e7ab94f443a7b47df0172154938d9c5c203a2921dbfa120950d69f81e43738853215069c7ef73c1f433a52327a971986290686b1e309fcac91d99
7
- data.tar.gz: f69591ef5c027b9585570c03d831b5d839e6990d310bae4c469e8ed70de6124620e7b7d280bc689a180bb3b74af1d260138172f11d51c5fcd5a7443cae6ff6a4
6
+ metadata.gz: fa9b8566cf79aa0470f1236c056bcd60f6968f2e3d50f39512431860758a3335363e32a1876610fde9d5a5ca4a72c7602a96779b83e8357c10088cdcb11fab93
7
+ data.tar.gz: cbe87bc0b7eb78ec264ab0e28dd48a36387b2f8325a8ec4d5d26666bda6f9755aeaefc1208687fabf56523865be9b9d96c70308137feda6260d21ab13223dab9
data/lib/ohm.rb CHANGED
@@ -838,7 +838,7 @@ module Ohm
838
838
  # to do it, you'll receive an Ohm::MissingID error.
839
839
  #
840
840
  def self.set(name, model)
841
- collections << name unless collections.include?(name)
841
+ track(name)
842
842
 
843
843
  define_method name do
844
844
  model = Utils.const(self.class, model)
@@ -868,7 +868,7 @@ module Ohm
868
868
  # to do it, you'll receive an Ohm::MissingID error.
869
869
  #
870
870
  def self.list(name, model)
871
- collections << name unless collections.include?(name)
871
+ track(name)
872
872
 
873
873
  define_method name do
874
874
  model = Utils.const(self.class, model)
@@ -1033,6 +1033,11 @@ module Ohm
1033
1033
  end
1034
1034
  end
1035
1035
 
1036
+ # Keep track of `key[name]` and remove when deleting the object.
1037
+ def self.track(name)
1038
+ tracked << name unless tracked.include?(name)
1039
+ end
1040
+
1036
1041
  # An Ohm::Set wrapper for Model.key[:all].
1037
1042
  def self.all
1038
1043
  Set.new(key[:all], key, self)
@@ -1279,7 +1284,7 @@ module Ohm
1279
1284
  "key" => key
1280
1285
  }.to_msgpack,
1281
1286
  uniques.to_msgpack,
1282
- model.collections.to_msgpack
1287
+ model.tracked.to_msgpack
1283
1288
  )
1284
1289
 
1285
1290
  return self
@@ -1344,8 +1349,8 @@ module Ohm
1344
1349
  @counters ||= []
1345
1350
  end
1346
1351
 
1347
- def self.collections
1348
- @collections ||= []
1352
+ def self.tracked
1353
+ @tracked ||= []
1349
1354
  end
1350
1355
 
1351
1356
  def self.attributes
@@ -1,6 +1,6 @@
1
1
  local model = cmsgpack.unpack(ARGV[1])
2
2
  local uniques = cmsgpack.unpack(ARGV[2])
3
- local collections = cmsgpack.unpack(ARGV[3])
3
+ local tracked = cmsgpack.unpack(ARGV[3])
4
4
 
5
5
  local function remove_indices(model)
6
6
  local memo = model.key .. ":_indices"
@@ -23,9 +23,9 @@ local function remove_uniques(model, uniques)
23
23
  end
24
24
  end
25
25
 
26
- local function remove_collections(model, collections)
27
- for _, collection in ipairs(collections) do
28
- local key = model.key .. ":" .. collection
26
+ local function remove_tracked(model, tracked)
27
+ for _, tracked_key in ipairs(tracked) do
28
+ local key = model.key .. ":" .. tracked_key
29
29
 
30
30
  redis.call("DEL", key)
31
31
  end
@@ -45,7 +45,7 @@ end
45
45
 
46
46
  remove_indices(model)
47
47
  remove_uniques(model, uniques)
48
- remove_collections(model, collections)
48
+ remove_tracked(model, tracked)
49
49
  delete(model)
50
50
 
51
51
  return model.id
data/ohm.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ohm"
3
- s.version = "2.0.0.alpha2"
3
+ s.version = "2.0.0.alpha3"
4
4
  s.summary = %{Object-hash mapping library for Redis.}
5
5
  s.description = %Q{Ohm is a library that allows to store an object in Redis, a persistent key-value database. It includes an extensible list of validations and has very good performance.}
6
6
  s.authors = ["Michel Martens", "Damian Janowski", "Cyril David"]
data/test/model.rb CHANGED
@@ -350,6 +350,7 @@ test "no leftover keys" do
350
350
  class ::Foo < Ohm::Model
351
351
  attribute :name
352
352
  index :name
353
+ track :notes
353
354
  end
354
355
 
355
356
  assert_equal [], Ohm.redis.call("KEYS", "*")
@@ -361,6 +362,18 @@ test "no leftover keys" do
361
362
 
362
363
  Foo[1].delete
363
364
  assert ["Foo:id"] == Ohm.redis.call("KEYS", "*")
365
+
366
+ Foo.create(:name => "Baz")
367
+
368
+ Ohm.redis.call("SET", Foo[2].key[:notes], "something")
369
+
370
+ expected = %w[Foo:2:_indices Foo:2 Foo:all Foo:id
371
+ Foo:indices:name:Baz Foo:2:notes]
372
+
373
+ assert_equal expected.sort, Ohm.redis.call("KEYS", "*").sort
374
+
375
+ Foo[2].delete
376
+ assert ["Foo:id"] == Ohm.redis.call("KEYS", "*")
364
377
  end
365
378
 
366
379
  # Listing
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha2
4
+ version: 2.0.0.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-30 00:00:00.000000000 Z
13
+ date: 2013-05-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redic
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  version: 1.3.1
141
141
  requirements: []
142
142
  rubyforge_project: ohm
143
- rubygems_version: 2.0.0
143
+ rubygems_version: 2.0.3
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Object-hash mapping library for Redis.