ohm 0.0.30 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ohm.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "base64"
4
4
  require File.join(File.dirname(__FILE__), "ohm", "redis")
5
5
  require File.join(File.dirname(__FILE__), "ohm", "validations")
6
+ require File.join(File.dirname(__FILE__), "ohm", "compat-1.8.6")
6
7
 
7
8
  module Ohm
8
9
 
@@ -0,0 +1,15 @@
1
+ unless "".respond_to?(:lines)
2
+ class String
3
+
4
+ # This version of String#lines is almost fully compatible with that
5
+ # of Ruby 1.9. If a zero-length record separator is supplied in Ruby
6
+ # 1.9, the string is split into paragraphs delimited by multiple
7
+ # successive newlines. This replacement ignores that feature in
8
+ # favor of code simplicity.
9
+ def lines(separator = $/)
10
+ result = split(separator).map { |part| "#{part}#{separator}" }
11
+ result.each { |r| yield r } if block_given?
12
+ result
13
+ end
14
+ end
15
+ end
data/lib/ohm/redis.rb CHANGED
@@ -54,7 +54,7 @@ module Ohm
54
54
  PROCESSOR_IDENTITY = lambda { |reply| reply }
55
55
  PROCESSOR_CONVERT_TO_BOOL = lambda { |reply| reply == 0 ? false : reply }
56
56
  PROCESSOR_SPLIT_KEYS = lambda { |reply| reply.split(" ") }
57
- PROCESSOR_INFO = lambda { |reply| Hash[*(reply.lines.map { |l| l.chomp.split(":") }.flatten)] }
57
+ PROCESSOR_INFO = lambda { |reply| Hash[*(reply.lines.map { |l| l.chomp.split(":", 2) }.flatten)] }
58
58
 
59
59
  REPLY_PROCESSOR = {
60
60
  :exists => PROCESSOR_CONVERT_TO_BOOL,
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class TestString < Test::Unit::TestCase
4
+ context "String#lines" do
5
+ should "return the parts when separated with \\n" do
6
+ assert_equal ["a\n", "b\n", "c\n"], "a\nb\nc\n".lines.to_a
7
+ end
8
+
9
+ should "return the parts when separated with \\r\\n" do
10
+ assert_equal ["a\r\n", "b\r\n", "c\r\n"], "a\r\nb\r\nc\r\n".lines.to_a
11
+ end
12
+
13
+ should "accept a record separator" do
14
+ assert_equal ["ax", "bx", "cx"], "axbxcx".lines("x").to_a
15
+ end
16
+
17
+ should "execute the passed block" do
18
+ lines = ["a\r\n", "b\r\n", "c\r\n"]
19
+
20
+ "a\r\nb\r\nc\r\n".lines do |line|
21
+ assert_equal lines.shift, line
22
+ end
23
+ end
24
+ end
25
+ end
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.30
4
+ version: 0.0.31
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-11-24 00:00:00 -03:00
13
+ date: 2009-11-26 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -25,6 +25,7 @@ extensions: []
25
25
  extra_rdoc_files: []
26
26
 
27
27
  files:
28
+ - lib/ohm/compat-1.8.6.rb
28
29
  - lib/ohm/redis.rb
29
30
  - lib/ohm/validations.rb
30
31
  - lib/ohm.rb
@@ -32,6 +33,7 @@ files:
32
33
  - LICENSE
33
34
  - Rakefile
34
35
  - Thorfile
36
+ - test/1.8.6_test.rb
35
37
  - test/all_tests.rb
36
38
  - test/benchmarks.rb
37
39
  - test/connection_test.rb