ohm 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ohm.rb CHANGED
@@ -459,7 +459,7 @@ module Ohm
459
459
  end
460
460
 
461
461
  def initialize(attrs = {})
462
- @_attributes = Hash.new {|hash,key| hash[key] = read_remote(key) }
462
+ @_attributes = Hash.new { |hash, key| hash[key] = read_remote(key) }
463
463
  update_attributes(attrs)
464
464
  end
465
465
 
@@ -474,7 +474,7 @@ module Ohm
474
474
  mutex do
475
475
  create_model_membership
476
476
  add_to_indices
477
- save!
477
+ write
478
478
  end
479
479
  end
480
480
 
@@ -484,7 +484,7 @@ module Ohm
484
484
 
485
485
  mutex do
486
486
  update_indices
487
- save!
487
+ write
488
488
  end
489
489
  end
490
490
 
@@ -561,6 +561,11 @@ module Ohm
561
561
  self.class.key(id, *args)
562
562
  end
563
563
 
564
+ def write
565
+ attributes.each { |att| write_remote(att, send(att)) }
566
+ self
567
+ end
568
+
564
569
  private
565
570
 
566
571
  def self.db
@@ -597,11 +602,6 @@ module Ohm
597
602
  db.srem(self.class.key(:all), id)
598
603
  end
599
604
 
600
- def save!
601
- attributes.each { |att| write_remote(att, send(att)) }
602
- self
603
- end
604
-
605
605
  def update_indices
606
606
  delete_from_indices
607
607
  add_to_indices
@@ -183,7 +183,7 @@ module Ohm
183
183
  def extract_bulk_argument(argv)
184
184
  if bulk_command?(argv)
185
185
  bulk = argv[-1].to_s
186
- argv[-1] = bulk.length
186
+ argv[-1] = bulk.respond_to?(:bytesize) ? bulk.bytesize : bulk.size
187
187
  bulk
188
188
  end
189
189
  end
@@ -7,7 +7,7 @@ class ConnectionTest < Test::Unit::TestCase
7
7
 
8
8
  test "connects lazily" do
9
9
  assert_nothing_raised do
10
- Ohm.connect(:port => 1234567)
10
+ Ohm.connect(:port => 9876)
11
11
  end
12
12
 
13
13
  assert_raises(Errno::ECONNREFUSED) do
@@ -23,6 +23,13 @@ class Event < Ohm::Model
23
23
  attribute :name
24
24
  counter :votes
25
25
  set :attendees, Person
26
+
27
+ attribute :slug
28
+
29
+ def write
30
+ self.slug = name.to_s.downcase
31
+ super
32
+ end
26
33
  end
27
34
 
28
35
  class TestRedis < Test::Unit::TestCase
@@ -46,7 +53,6 @@ class TestRedis < Test::Unit::TestCase
46
53
  end
47
54
 
48
55
  context "An event updated from a hash of attributes" do
49
-
50
56
  class Meetup < Ohm::Model
51
57
  attribute :name
52
58
 
@@ -146,6 +152,12 @@ class TestRedis < Test::Unit::TestCase
146
152
 
147
153
  assert_equal "Lorem", Event[event.id].name
148
154
  end
155
+
156
+ should "allow to hook into write" do
157
+ event = Event.create(:name => "Foo")
158
+
159
+ assert_equal "foo", event.slug
160
+ end
149
161
  end
150
162
 
151
163
  context "Delete" do
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: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-16 00:00:00 -03:00
13
+ date: 2009-09-21 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies: []
16
16