Permalink
Browse files

works much better now

  • Loading branch information...
BrianTheCoder committed Nov 14, 2009
1 parent 7954c36 commit 3315b37bc816ba2e6d6ffa920710cb37e2c80355
Showing with 20 additions and 17 deletions.
  1. +4 −4 example/types.rb
  2. +5 −7 lib/redis/data_types.rb
  3. +8 −4 lib/redis/field_proxy.rb
  4. +1 −1 lib/redis/set.rb
  5. +2 −1 redis-types.gemspec
View
@@ -34,9 +34,9 @@ class User
u = User.new(:id => 1)
-p u.name.get
-p u.created.get.strftime('%m/%d/%Y')
-p u.profile.get
+p u.name
+p u.created.strftime('%m/%d/%Y')
+p u.profile
p u.posts[0,20]
-p u.posts[0]
+p u.posts[0]
p u.followers.has_key?(2)
View
@@ -1,21 +1,19 @@
class Redis
module DataTypes
- TYPES = %w(String Integer Float EpochTime DateTime Json Yaml IPAddress FilePath Uri Slug)
+ TYPES = %w(Integer Float EpochTime DateTime Json Yaml IPAddress FilePath Uri Slug)
def self.define_data_types
TYPES.each do |data_type|
if Object.const_defined?(data_type)
klass = Object.const_get(data_type)
else
klass = Object.const_set(data_type, Class.new)
end
- klass.extend const_get(data_type)
+ if const_defined?(data_type)
+ klass.extend const_get(data_type)
+ end
end
end
-
- FROM = Proc.new{|value| value }
-
- TO = Proc.new{|value| value.to_s }
-
+
module Integer
def from_redis(value); value && value.to_i end
end
View
@@ -6,7 +6,7 @@ def initialize(redis, marshal)
@redis = redis
@key = key
@marshal = marshal
- validate_marshal
+ check_for_redis_serialization
end
def method_missing(method, *argv)
@@ -17,9 +17,13 @@ def method_missing(method, *argv)
protected
- def validate_mashal
- @marshal.extend Redis::DataTypes::TO unless @marshal.responds_to?(:to_redis)
- @marshal.extend Redis::DataTypes::FROM unless @marshal.responds_to?(:from_redis)
+ def check_for_redis_serialization
+ unless @marshal.respond_to?(:to_redis)
+ @marshal.instance_eval "def to_redis(value); value.to_s end"
+ end
+ unless @marshal.respond_to?(:from_redis)
+ @marshal.instance_eval "def from_redis(value); value end"
+ end
end
def translate_method_name(m); m; end
View
@@ -11,7 +11,7 @@ def <<(value); redis.sadd key, marshal.to_redis(value) end
def delete(value); redis.srem key, marshal.to_redis(value) end
- def include?(value); redis.sismember(key, marshal.to_redis(value)) == 1 end
+ def include?(value); redis.sismember(key, marshal.to_redis(value)) end
alias_method :add, :<<
alias_method :remove, :delete
View
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{redis-types}
- s.version = "0.1.0"
+ s.version = "0.1.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["brianthecoder"]
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
"lib/redis/set.rb",
"lib/redis/types.rb",
"lib/redis/value.rb",
+ "redis-types.gemspec",
"spec/dump.rdb",
"spec/redis/types_spec.rb",
"spec/spec.opts",

0 comments on commit 3315b37

Please sign in to comment.