ohm 2.0.0 → 2.0.1

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: b6a988b7d453e4d23906662c7fd1d8d993634892
4
- data.tar.gz: 4673e7432655aeb8b9061d184ff912cb35ac42d3
3
+ metadata.gz: 6d404b17a73aaa3f8e44ef1973cc2c2281bfdeb7
4
+ data.tar.gz: 5e59ffee49a2bee96c3417cc0763f31552bf06ff
5
5
  SHA512:
6
- metadata.gz: b315cdda1f6011e68b2c1f194f229fc1b757d1cf8b40548df5852f8f5c96b8fe0a7dfb20c43ff8614f9bdd0905b367bab098e6ba209c389ce925859696b09dec
7
- data.tar.gz: a64327f9085061116c85d50d63d3719d47b3521833bc72374fa3094444ca6b7d9f4ee1a747497b27b09d4c1bf02b9b6ac54075c0f5b230f3d6c6e4ae0a3cf233
6
+ metadata.gz: 849b95d5ebfc61b136be8351b6c0887e6c2961c78bb086204c39a1110524efd02fe94d48c5ed05c123c326567aa70ffbb2292e70a10d9f875307dd33e82f72e9
7
+ data.tar.gz: db2213eff5791aa09f02e2d79c9059d9ed4d3619f6206257bf3a69c227a2481361f179fd620ec6b07d4c21f7cb89965d6e52e7b90ab08494ef8ed067e637aa31
data/.gems CHANGED
@@ -1,4 +1,4 @@
1
- cutest -v 1.2.0
1
+ cutest -v 1.2.1
2
2
  msgpack -v 0.5.8
3
3
  nido -v 0.0.1
4
- redic -v 1.0.1
4
+ redic -v 1.1.0
data/README.md CHANGED
@@ -25,6 +25,7 @@ These are libraries in other languages that were inspired by Ohm.
25
25
  * [Lohm](https://github.com/slact/lua-ohm) for Lua, created by slact
26
26
  * [Nohm](https://github.com/maritz/nohm) for Node.js, created by maritz
27
27
  * [Redisco](https://github.com/iamteem/redisco) for Python, created by iamteem
28
+ * [redis3m](https://github.com/luca3m/redis3m) for C++, created by luca3m
28
29
 
29
30
  Articles and Presentations
30
31
  --------------------------
@@ -8,7 +8,7 @@
8
8
  #
9
9
  # Beyond that, Ohm doesn't try to hide Redis, but rather exposes it in
10
10
  # a simple way, through key hierarchies provided by the library
11
- # [Nest](http://github.com/soveran/nest).
11
+ # [Nido](http://github.com/soveran/nido).
12
12
 
13
13
  # Let's require `Ohm`. We also require `Ohm::Contrib` so we can make
14
14
  # use of its module `Ohm::Callbacks`.
@@ -25,34 +25,27 @@ class Post < Ohm::Model
25
25
  attribute :title
26
26
  index :title
27
27
 
28
- list :comments, Comment
28
+ list :comments, :Comment
29
29
 
30
- # This is one example of using the underlying library `Nest` directly.
31
- # As you can see, we can easily drop down to using raw *Redis* commands,
32
- # in this case we use
33
- # [ZREVRANGE](http://code.google.com/p/redis/wiki/ZrangeCommand).
34
- #
35
- # *Note:* Since `Ohm::Model` defines a `to_proc`, we can use the `&` syntax
36
- # together with `map` to make our code a little more terse.
30
+ # This is one example of using Redic simple API and
31
+ # the underlying library `Nido`.
37
32
  def self.latest
38
- key[:latest].zrevrange(0, -1).map(&Post)
33
+ fetch(redis.call("ZRANGE", key[:latest], 0, -1))
39
34
  end
40
35
 
36
+ protected
37
+
41
38
  # Here we just quickly push this instance of `Post` to our `latest`
42
39
  # *SORTED SET*. We use the current time as the score.
43
- protected
44
40
  def after_save
45
- self.class.key[:latest].zadd(Time.now.to_i, id)
41
+ redis.call("ZADD", model.key[:latest], Time.now.to_i, id)
46
42
  end
47
43
 
48
44
  # Since we add every `Post` to our *SORTED SET*, we have to make sure that
49
45
  # we removed it from our `latest` *SORTED SET* as soon as we delete a
50
46
  # `Post`.
51
- #
52
- # In this case we use the raw *Redis* command
53
- # [ZREM](http://code.google.com/p/redis/wiki/ZremCommand).
54
47
  def after_delete
55
- self.class.key[:latest].zrem(id)
48
+ redis.call("ZREM", model.key[:latest], id)
56
49
  end
57
50
  end
58
51
 
@@ -68,32 +61,35 @@ require "cutest"
68
61
 
69
62
  # To make it simple, we also ensure that every test run has a clean
70
63
  # *Redis* instance.
71
- prepare { Ohm.flush }
64
+ prepare do
65
+ Ohm.flush
66
+ end
72
67
 
73
- # Now let's create Post. `Cutest` by default yields the return value of the
68
+ # Now let's create a post. `Cutest` by default yields the return value of the
74
69
  # block to each and every one of the test blocks.
75
- setup { Post.create }
70
+ setup do
71
+ Post.create
72
+ end
76
73
 
77
74
  # We then verify the behavior for our `Post:latest` ZSET. Our created
78
75
  # post should automatically be part of `Post:latest`.
79
- test "created post is inserted into latest" do |p|
80
- assert [p.id] == Post.key[:latest].zrange(0, -1)
76
+ test "created post is inserted into latest" do |post|
77
+ assert [post.id] == Post.latest.map(&:id)
81
78
  end
82
79
 
83
80
  # And it should automatically be removed from it as soon as we delete our
84
81
  # `Post`.
85
- test "deleting the created post removes it from latest" do |p|
86
- p.delete
82
+ test "deleting the created post removes it from latest" do |post|
83
+ post.delete
87
84
 
88
- assert Post.key[:latest].zrange(0, -1).empty?
85
+ assert Post.latest.empty?
89
86
  end
90
87
 
91
88
  # You might be curious what happens when we do `Post.all`. The test here
92
89
  # demonstrates more or less what's happening when you do that.
93
- test "querying Post:all using raw Redis commands" do |p|
94
- assert [p.id] == Post.key[:all].smembers
95
-
96
- assert [p] == Post.key[:all].smembers.map(&Post)
90
+ test "querying Post:all using raw Redis commands" do |post|
91
+ assert [post.id] == Post.all.ids
92
+ assert [post] == Post.all.to_a
97
93
  end
98
94
 
99
95
  #### Understanding `post.comments`.
@@ -102,48 +98,40 @@ end
102
98
  # `post.comments` object.
103
99
 
104
100
  # Getting the current size of our comments is just a wrapper for
105
- # [LLEN](http://code.google.com/p/redis/wiki/LlenCommand).
106
- test "checking the number of comments for a given post" do |p|
107
- assert 0 == p.comments.key.llen
108
- assert 0 == p.comments.size
101
+ # [LLEN](http://redis.io/commands/LLEN).
102
+ test "checking the number of comments for a given post" do |post|
103
+ assert_equal 0, post.comments.size
104
+ assert_equal 0, Post.redis.call("LLEN", post.comments.key)
109
105
  end
110
106
 
111
107
  # Also, pushing a comment to our `post.comments` object is equivalent
112
- # to doing an [RPUSH](http://code.google.com/p/redis/wiki/RpushCommand)
113
- # of its `id`.
114
- test "pushing a Comment manually and checking for its presence" do |p|
108
+ # to doing an [RPUSH](http://redis.io/commands/RPUSH) of its `id`.
109
+ test "pushing a comment manually and checking for its presence" do |post|
115
110
  comment = Comment.create
116
111
 
117
- p.comments.key.rpush(comment.id)
118
- assert [comment.id] == p.comments.key.lrange(0, -1)
112
+ Post.redis.call("RPUSH", post.comments.key, comment.id)
113
+ assert_equal comment, post.comments.last
114
+
115
+ post.comments.push(comment)
116
+ assert_equal comment, post.comments.last
119
117
  end
120
118
 
121
- # Now for some interesting judo
119
+ # Now for some interesting judo.
122
120
  test "now what if we want to find all Ohm or Redis posts" do
123
- ohm = Post.create(:title => "Ohm")
124
- redis = Post.create(:title => "Redis")
125
-
126
- # Let's first choose an arbitrary key name to hold our `Set`.
127
- ohm_redis = Post.key.volatile["ohm-redis"]
128
-
129
- # A *volatile* key just simply means it will be prefixed with a `~`.
130
- assert "~:Post:ohm-redis" == ohm_redis
121
+ ohm = Post.create(title: "Ohm")
122
+ redis = Post.create(title: "Redis")
131
123
 
132
124
  # Finding all *Ohm* or *Redis* posts now will just be a call to
133
- # [SUNIONSTORE](http://code.google.com/p/redis/wiki/SunionstoreCommand)
134
- # on our *volatile* `ohm-redis` key.
135
- ohm_redis.sunionstore(
136
- Post.index_key_for(:title, "Ohm"),
137
- Post.index_key_for(:title, "Redis")
138
- )
125
+ # [SUNIONSTORE](http://redis.io/commands/UNIONSTORE).
126
+ result = Post.find(title: "Ohm").union(title: "Redis")
139
127
 
140
128
  # And voila, they have been found!
141
- assert [ohm.id, redis.id] == ohm_redis.smembers.sort
129
+ assert_equal [ohm, redis], result.to_a
142
130
  end
143
131
 
144
132
  #### The command reference is your friend
145
133
 
146
134
  # If you invest a little time reading through all the different
147
- # [Redis commands](http://code.google.com/p/redis/wiki/CommandReference),
148
- # I'm pretty sure you will enjoy your experience hacking with Ohm, Nest and
149
- # Redis a lot more.
135
+ # [Redis commands](http://redis.io/commands).
136
+ # I'm pretty sure you will enjoy your experience hacking with Ohm, Nido,
137
+ # Redic and Redis a lot more.
data/lib/ohm.rb CHANGED
@@ -611,7 +611,7 @@ module Ohm
611
611
  end
612
612
 
613
613
  # Anytime you filter a set with more than one requirement, you
614
- # internally use a `MultiSet`. `MutiSet` is a bit slower than just
614
+ # internally use a `MultiSet`. `MultiSet` is a bit slower than just
615
615
  # a `Set` because it has to `SINTERSTORE` all the keys prior to
616
616
  # retrieving the members, size, etc.
617
617
  #
@@ -775,7 +775,7 @@ module Ohm
775
775
  end
776
776
 
777
777
  def self.mutex
778
- @mutex ||= Mutex.new
778
+ @@mutex ||= Mutex.new
779
779
  end
780
780
 
781
781
  def self.synchronize(&block)
@@ -1074,23 +1074,36 @@ module Ohm
1074
1074
  # persisted attributes. All attributes are stored on the Redis
1075
1075
  # hash.
1076
1076
  #
1077
- # Example:
1078
1077
  # class User < Ohm::Model
1079
1078
  # attribute :name
1080
1079
  # end
1081
1080
  #
1082
- # # It's the same as:
1081
+ # user = User.new(name: "John")
1082
+ # user.name
1083
+ # # => "John"
1083
1084
  #
1084
- # class User < Ohm::Model
1085
- # def name
1086
- # @attributes[:name]
1087
- # end
1085
+ # user.name = "Jane"
1086
+ # user.name
1087
+ # # => "Jane"
1088
1088
  #
1089
- # def name=(name)
1090
- # @attributes[:name] = name
1091
- # end
1089
+ # A +lambda+ can be passed as a second parameter to add
1090
+ # typecasting support to the attribute.
1091
+ #
1092
+ # class User < Ohm::Model
1093
+ # attribute :age, ->(x) { x.to_i }
1092
1094
  # end
1093
1095
  #
1096
+ # user = User.new(age: 100)
1097
+ #
1098
+ # user.age
1099
+ # # => 100
1100
+ #
1101
+ # user.age.kind_of?(Integer)
1102
+ # # => true
1103
+ #
1104
+ # Check http://rubydoc.info/github/cyx/ohm-contrib#Ohm__DataTypes
1105
+ # to see more examples about the typecasting feature.
1106
+ #
1094
1107
  def self.attribute(name, cast = nil)
1095
1108
  attributes << name unless attributes.include?(name)
1096
1109
 
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"
3
+ s.version = "2.0.1"
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 has very good performance.}
6
6
  s.authors = ["Michel Martens", "Damian Janowski", "Cyril David"]
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
4
+ version: 2.0.1
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: 2014-03-18 00:00:00.000000000 Z
13
+ date: 2014-06-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redic
@@ -106,7 +106,6 @@ files:
106
106
  - test/connection.rb
107
107
  - test/core.rb
108
108
  - test/counters.rb
109
- - test/db/.gitignore
110
109
  - test/enumerable.rb
111
110
  - test/filtering.rb
112
111
  - test/hash_key.rb
@@ -116,7 +115,6 @@ files:
116
115
  - test/list.rb
117
116
  - test/model.rb
118
117
  - test/set.rb
119
- - test/test.conf
120
118
  - test/thread_safety.rb
121
119
  - test/to_hash.rb
122
120
  - test/uniques.rb
data/test/test.conf DELETED
@@ -1,8 +0,0 @@
1
- dir ./test/db
2
- pidfile ./redis.pid
3
- port 6379
4
- timeout 300
5
- loglevel debug
6
- logfile stdout
7
- databases 16
8
- daemonize yes