ohm 0.0.33 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,3 +1,29 @@
1
- task :default do
2
- exec "thor ohm:test"
1
+ require "rake/testtask"
2
+
3
+ REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
4
+ REDIS_CNF = File.join(REDIS_DIR, "test.conf")
5
+ REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
6
+
7
+ task :default => :run
8
+
9
+ desc "Run tests and manage server start/stop"
10
+ task :run => [:start, :test, :stop]
11
+
12
+ desc "Start the Redis server"
13
+ task :start do
14
+ unless File.exists?(REDIS_PID)
15
+ system "redis-server #{REDIS_CNF}"
16
+ end
17
+ end
18
+
19
+ desc "Stop the Redis server"
20
+ task :stop do
21
+ if File.exists?(REDIS_PID)
22
+ system "kill #{File.read(REDIS_PID)}"
23
+ system "rm #{REDIS_PID}"
24
+ end
25
+ end
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.pattern = 'test/**/*_test.rb'
3
29
  end
data/Thorfile CHANGED
@@ -17,25 +17,4 @@ class Ohm < Thor
17
17
  def deploy
18
18
  system "rsync -az doc/* ohm.keyvalue.org:deploys/ohm.keyvalue.org/"
19
19
  end
20
-
21
- desc "test", "Run all tests"
22
- def test
23
- invoke "ohm:redis:start"
24
-
25
- Dir["test/**/*_test.rb"].each do |file|
26
- load file
27
- end
28
- end
29
-
30
- class Redis < Thor
31
- desc "start", "Start Redis server"
32
- def start
33
- %x{dtach -n /tmp/ohm.dtach redis-server test/test.conf}
34
- end
35
-
36
- desc "attach", "Attach to Redis server"
37
- def attach
38
- %x{dtach -a /tmp/ohm.dtach}
39
- end
40
- end
41
20
  end
data/lib/ohm/key.rb CHANGED
@@ -16,6 +16,10 @@ module Ohm
16
16
  @namespace = namespace
17
17
  end
18
18
 
19
+ def sub_keys
20
+ parts.map {|k| k.glue == ":" ? k : k.volatile }
21
+ end
22
+
19
23
  def append(*parts)
20
24
  @parts += parts
21
25
  self
data/lib/ohm/redis.rb CHANGED
@@ -53,7 +53,7 @@ module Ohm
53
53
 
54
54
  PROCESSOR_IDENTITY = lambda { |reply| reply }
55
55
  PROCESSOR_CONVERT_TO_BOOL = lambda { |reply| reply == 0 ? false : reply }
56
- PROCESSOR_SPLIT_KEYS = lambda { |reply| reply.split(" ") }
56
+ PROCESSOR_SPLIT_KEYS = lambda { |reply| reply.respond_to?(:split) ? reply.split(" ") : reply }
57
57
  PROCESSOR_INFO = lambda { |reply| Hash[*(reply.lines.map { |l| l.chomp.split(":", 2) }.flatten)] }
58
58
 
59
59
  REPLY_PROCESSOR = {
data/lib/ohm.rb CHANGED
@@ -8,6 +8,7 @@ require File.join(File.dirname(__FILE__), "ohm", "key")
8
8
  require File.join(File.dirname(__FILE__), "ohm", "collection")
9
9
 
10
10
  module Ohm
11
+ VERSION = "0.0.34"
11
12
 
12
13
  # Provides access to the Redis database. This is shared accross all models and instances.
13
14
  def redis
@@ -195,7 +196,7 @@ module Ohm
195
196
  # Apply a redis operation on a collection of sets.
196
197
  def apply(operation, hash, glue)
197
198
  target = key.volatile.group(glue).append(*keys(hash))
198
- model.db.send(operation, target, *target.parts)
199
+ model.db.send(operation, target, *target.sub_keys)
199
200
  Set.new(target, model)
200
201
  end
201
202
 
@@ -215,6 +216,22 @@ module Ohm
215
216
  class List < Collection
216
217
  Raw = Ohm::List
217
218
 
219
+ def shift
220
+ if id = raw.shift
221
+ model[id]
222
+ end
223
+ end
224
+
225
+ def pop
226
+ if id = raw.pop
227
+ model[id]
228
+ end
229
+ end
230
+
231
+ def unshift(model)
232
+ raw.unshift(model.id)
233
+ end
234
+
218
235
  def inspect
219
236
  "#<List (#{model}): #{all.inspect}>"
220
237
  end
data/test/indices_test.rb CHANGED
@@ -33,7 +33,7 @@ class IndicesTest < Test::Unit::TestCase
33
33
 
34
34
  context "A model with an indexed attribute" do
35
35
  setup do
36
- @user1 = User.create(:email => "foo", :activation_code => "bar")
36
+ @user1 = User.create(:email => "foo", :activation_code => "bar", :update => "baz")
37
37
  @user2 = User.create(:email => "bar")
38
38
  @user3 = User.create(:email => "baz qux")
39
39
  end
@@ -48,8 +48,8 @@ class IndicesTest < Test::Unit::TestCase
48
48
  assert_equal "~:IndicesTest::User:email:Zm9v+IndicesTest::User:activation_code:",
49
49
  User.find(:email => "foo").find(:activation_code => "").key.to_s
50
50
 
51
- assert_equal "~:IndicesTest::User:email:Zm9v+IndicesTest::User:activation_code:+IndicesTest::User:working_days:",
52
- User.find(:email => "foo").find(:activation_code => "").find(:working_days => "").key.to_s
51
+ assert_equal "~:~:IndicesTest::User:email:Zm9v+IndicesTest::User:activation_code:YmFy+IndicesTest::User:update:YmF6",
52
+ result = User.find(:email => "foo").find(:activation_code => "bar").find(:update => "baz").key.to_s
53
53
  end
54
54
 
55
55
  should "use a special namespace for set operations" do
@@ -58,6 +58,10 @@ class IndicesTest < Test::Unit::TestCase
58
58
  assert Ohm.redis.keys("~:*").size > 0
59
59
  end
60
60
 
61
+ should "allow multiple chained finds" do
62
+ assert_equal 1, User.find(:email => "foo").find(:activation_code => "bar").find(:update => "baz").size
63
+ end
64
+
61
65
  should "raise if the field is not indexed" do
62
66
  assert_raises(Ohm::Model::IndexNotFound) do
63
67
  User.find(:sandunga => "foo")
data/test/model_test.rb CHANGED
@@ -450,6 +450,8 @@ class TestRedis < Test::Unit::TestCase
450
450
 
451
451
  context "Attributes of type List" do
452
452
  setup do
453
+ Ohm.flush
454
+
453
455
  @post = Post.new
454
456
  @post.body = "Hello world!"
455
457
  @post.create
@@ -551,6 +553,19 @@ class TestRedis < Test::Unit::TestCase
551
553
  assert @post.related.include?(another_post)
552
554
  assert !@post.related.include?(Post.create)
553
555
  end
556
+
557
+ should "unshift models" do
558
+ @post.related.unshift(Post.create(:body => "Hello"))
559
+ @post.related.unshift(Post.create(:body => "Goodbye"))
560
+
561
+ assert_equal ["3", "2"], @post.related.raw
562
+
563
+ assert_equal "3", @post.related.shift.id
564
+
565
+ assert_equal "2", @post.related.pop.id
566
+
567
+ assert_nil @post.related.pop
568
+ end
554
569
  end
555
570
 
556
571
  context "Applying arbitrary transformations" do
data/test/test.conf CHANGED
@@ -2,11 +2,7 @@ dir ./test/db
2
2
  pidfile ./redis.pid
3
3
  port 6381
4
4
  timeout 300
5
-
6
- save 900 10000
7
-
8
5
  loglevel debug
9
-
10
6
  logfile stdout
11
-
12
7
  databases 16
8
+ daemonize yes
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 34
9
+ version: 0.0.34
5
10
  platform: ruby
6
11
  authors:
7
12
  - Michel Martens
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-03-03 00:00:00 -03:00
18
+ date: 2010-04-03 00:00:00 -03:00
14
19
  default_executable:
15
20
  dependencies: []
16
21
 
@@ -60,18 +65,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
65
  requirements:
61
66
  - - ">="
62
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
63
70
  version: "0"
64
- version:
65
71
  required_rubygems_version: !ruby/object:Gem::Requirement
66
72
  requirements:
67
73
  - - ">="
68
74
  - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
69
77
  version: "0"
70
- version:
71
78
  requirements: []
72
79
 
73
80
  rubyforge_project: ohm
74
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.3.6
75
82
  signing_key:
76
83
  specification_version: 3
77
84
  summary: Object-hash mapping library for Redis.