ohm 2.0.0.alpha4 → 2.0.0.alpha5

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: 0098b213347fa1dade66ecb25578c98661dede1f
4
- data.tar.gz: bf14fe6201dcc44633250fe1c76efd1ee9319d41
3
+ metadata.gz: eddfa837c7904b72acba3e95ea9af454412bef88
4
+ data.tar.gz: de756a4ef37ea55738cea7636a251a411da4cabd
5
5
  SHA512:
6
- metadata.gz: 6452603dcdc4f3d0d822243c6d85d30d73d012f3521d04f673c5c53a8d71e6a153b7fada6420f889ef389f50e2d0ad2994b2985c239820471270a3d4c0410114
7
- data.tar.gz: f1877e6cc349845df64382b0aa65f9f61955db0dd28f5e41ca47b6047d5625eb44b8bafbb0a1bb46dc0136641d98ebf786077f322672e8552d4edf323113bcca
6
+ metadata.gz: cc35a4e810775b5350ccd255035b2659b5559aa277d91a0f4584bf417bf663d4d27173d64ef324c7d305aba6eda8cc1f96bfde9ab71ead4f237b7382613cad45
7
+ data.tar.gz: 6314ece218f9ad0f82548dfb99b44db51979d14e8282277ae1abb9f4dfba5c96a68cadd8ec573efe6d475aeb0315b33aded1ce26862c28b3ff8cc6be8d761bfb
data/lib/ohm.rb CHANGED
@@ -1244,13 +1244,16 @@ module Ohm
1244
1244
  uniques = {}
1245
1245
  model.uniques.each { |field| uniques[field] = send(field) }
1246
1246
 
1247
- _initialize_id if new?
1247
+ features = {
1248
+ "name" => model.name
1249
+ }
1250
+
1251
+ if defined?(@id)
1252
+ features["id"] = @id
1253
+ end
1248
1254
 
1249
1255
  response = script(LUA_SAVE, 0,
1250
- { "name" => model.name,
1251
- "id" => id,
1252
- "key" => key
1253
- }.to_msgpack,
1256
+ features.to_msgpack,
1254
1257
  _sanitized_attributes.to_msgpack,
1255
1258
  indices.to_msgpack,
1256
1259
  uniques.to_msgpack
@@ -1264,6 +1267,8 @@ module Ohm
1264
1267
  end
1265
1268
  end
1266
1269
 
1270
+ @id = response
1271
+
1267
1272
  return self
1268
1273
  end
1269
1274
 
@@ -1378,10 +1383,6 @@ module Ohm
1378
1383
  end
1379
1384
  end
1380
1385
 
1381
- def self.new_id
1382
- redis.call("INCR", key[:id])
1383
- end
1384
-
1385
1386
  attr_writer :id
1386
1387
 
1387
1388
  def model
@@ -1392,10 +1393,6 @@ module Ohm
1392
1393
  model.redis
1393
1394
  end
1394
1395
 
1395
- def _initialize_id
1396
- @id = model.new_id.to_s
1397
- end
1398
-
1399
1396
  def _sanitized_attributes
1400
1397
  result = []
1401
1398
 
@@ -35,6 +35,12 @@ local indices = cmsgpack.unpack(ARGV[3])
35
35
  local uniques = cmsgpack.unpack(ARGV[4])
36
36
 
37
37
  local function save(model, attrs)
38
+ if model.id == nil then
39
+ model.id = redis.call("INCR", model.name .. ":id")
40
+ end
41
+
42
+ model.key = model.name .. ":" .. model.id
43
+
38
44
  redis.call("SADD", model.name .. ":all", model.id)
39
45
  redis.call("DEL", model.key)
40
46
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ohm"
3
- s.version = "2.0.0.alpha4"
3
+ s.version = "2.0.0.alpha5"
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"]
@@ -16,8 +16,8 @@ test "assign an ID and save the object" do
16
16
  event1 = Event.create(:name => "Ruby Tuesday")
17
17
  event2 = Event.create(:name => "Ruby Meetup")
18
18
 
19
- assert_equal "1", event1.id
20
- assert_equal "2", event2.id
19
+ assert_equal "1", event1.id.to_s
20
+ assert_equal "2", event2.id.to_s
21
21
  end
22
22
 
23
23
  test "save the attributes in UTF8" do
@@ -32,7 +32,7 @@ scope do
32
32
 
33
33
  test "select" do |john, jane|
34
34
  assert_equal 2, Contact.all.count
35
- assert_equal [john], Contact.all.select { |c| c.id == john.id }
35
+ assert_equal [john], Contact.all.select { |c| c.id.to_s == john.id.to_s }
36
36
  end
37
37
  end
38
38
 
@@ -33,12 +33,12 @@ end
33
33
 
34
34
  test "export a hash with the its id" do
35
35
  person = Venue.create(:name => "John Doe")
36
- assert Hash[:id => '1'] == person.to_hash
36
+ assert_equal Hash[:id => 1], person.to_hash
37
37
  end
38
38
 
39
39
  test "return the merged attributes" do
40
40
  programmer = Programmer.create(:language => "Ruby")
41
- expected_hash = { :id => '1', :language => 'Ruby' }
41
+ expected_hash = { :id => 1, :language => 'Ruby' }
42
42
 
43
43
  assert expected_hash == programmer.to_hash
44
44
  end
@@ -47,7 +47,7 @@ test "just be the to_hash of a model" do
47
47
  json = JSON.parse(Programmer.create(:language => "Ruby").to_json)
48
48
 
49
49
  assert ["id", "language"] == json.keys.sort
50
- assert "1" == json["id"]
50
+ assert 1 == json["id"]
51
51
  assert "Ruby" == json["language"]
52
52
  end
53
53
 
@@ -57,12 +57,6 @@ class Meetup < Ohm::Model
57
57
  end
58
58
  end
59
59
 
60
- class Invoice < Ohm::Model
61
- def _initialize_id
62
- @id = "_custom_id"
63
- end
64
- end
65
-
66
60
  test "booleans" do
67
61
  post = Post.new(body: true, published: false)
68
62
 
@@ -77,15 +71,6 @@ test "booleans" do
77
71
  assert_equal nil, post.published
78
72
  end
79
73
 
80
- test "customized ID" do
81
- inv = Invoice.create
82
- assert_equal "_custom_id", inv.id
83
-
84
- i = Invoice.create(:id => "_diff_id")
85
- assert_equal "_diff_id", i.id
86
- assert_equal i, Invoice["_diff_id"]
87
- end
88
-
89
74
  test "empty model is ok" do
90
75
  class Foo < Ohm::Model
91
76
  end
@@ -135,8 +120,8 @@ test "assign an ID and save the object" do
135
120
  event1 = Event.create(:name => "Ruby Tuesday")
136
121
  event2 = Event.create(:name => "Ruby Meetup")
137
122
 
138
- assert "1" == event1.id
139
- assert "2" == event2.id
123
+ assert 1 == event1.id
124
+ assert 2 == event2.id
140
125
  end
141
126
 
142
127
  test "updates attributes" do
@@ -286,8 +271,8 @@ test "assign a new id to the event" do
286
271
  assert !event1.new?
287
272
  assert !event2.new?
288
273
 
289
- assert "1" == event1.id
290
- assert "2" == event2.id
274
+ assert 1 == event1.id
275
+ assert 2 == event2.id
291
276
  end
292
277
 
293
278
  # Saving a model
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.alpha4
4
+ version: 2.0.0.alpha5
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-10-03 00:00:00.000000000 Z
13
+ date: 2013-10-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redic