Permalink
Browse files

minor tweaks

  • Loading branch information...
1 parent 3b183ed commit da9eaf7e92e827d123f3c4ab644099be81bb7554 @BrianTheCoder committed Feb 7, 2010
Showing with 43 additions and 16 deletions.
  1. +1 −1 VERSION
  2. +5 −1 lib/redis/field_proxy.rb
  3. +25 −9 lib/redis/types.rb
  4. +7 −2 lib/redis/value.rb
  5. +5 −3 redis-types.gemspec
View
@@ -1 +1 @@
-0.2.0
+0.1.6
View
@@ -9,14 +9,18 @@ def initialize(redis, marshal)
end
def marshal
- @_mashall ||= @marshal.is_a?(String) ? Object.const_get(@marshal) : @marshal
+ @_mashall ||= @marshal == String ? Object.const_get(@marshal) : @marshal
end
def method_missing(method, *argv)
translated_method = translate_method_name(method)
raise NoMethodError.new("Method '#{method}' is not defined") unless translated_method
@redis.send translated_method, @key, *argv
end
+
+ def destroy
+ @redis.delete(key)
+ end
protected
View
@@ -35,19 +35,19 @@ def redis_fields; @_redis_fields ||= {}; end
def indexes; @_indexes ||= {}; end
- def set(name, type = 'String', opts = {})
+ def set(name, type = String, opts = {})
redis_field(name, type, ::Redis::Set)
end
- def list(name, type = 'String', opts = {})
+ def list(name, type = String, opts = {})
redis_field(name, type, ::Redis::List)
end
- def value(name, type = 'String', opts = {})
+ def value(name, type = String, opts = {})
redis_field(name, type, ::Redis::Value)
end
- def zset(name, type = 'String', opts = {})
+ def zset(name, type = String, opts = {})
redis_field(name, type, ::Redis::Zset)
end
@@ -59,17 +59,27 @@ def redis
end
end
- def redis=(redis); @redis = redis end
+ def redis=(redis)
+ @redis = redis
+ end
- def delete(id); self.find(id).destroy end
+ def delete(key)
+ self.find(key).destroy
+ end
- def find(id); self.new(:id => id) end
+ def find(key)
+ self.new(:id => key)
+ end
alias :[] :find
- def to_redis(value); value.id.to_s end
+ def to_redis(value)
+ value.id.to_s
+ end
- def from_redis(value); [id] end
+ def from_redis(value)
+ find(id)
+ end
private
@@ -134,6 +144,12 @@ def []=(method, value)
send(:"#{method}=", value)
end
+ def attributes
+ self.class.redis_fields.inject({}) do |hsh, (key, value)|
+ hsh[key] = self[key]
+ end
+ end
+
def destroy(name = nil)
if name
redis.delete field_key(name.to_s)
View
@@ -1,7 +1,12 @@
class Redis::Value
include Redis::FieldProxy
- def set(value); redis[key] = marshal.to_redis(value) end
+ def set(value)
+ return if value.nil?
+ redis[key] = marshal.to_redis(value)
+ end
- def get; marshal.from_redis(redis[key]) end
+ def get
+ marshal.from_redis(redis[key])
+ end
end
View
@@ -5,16 +5,17 @@
Gem::Specification.new do |s|
s.name = %q{redis-types}
- s.version = "0.1.5"
+ s.version = "0.1.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["brianthecoder"]
- s.date = %q{2009-11-14}
+ s.date = %q{2010-01-27}
s.description = %q{this is so awesome it makes grown men cry}
s.email = %q{wbsmith83@gmail.com}
s.extra_rdoc_files = [
"LICENSE",
- "README.rdoc"
+ "README.rdoc",
+ "TODO"
]
s.files = [
".document",
@@ -32,6 +33,7 @@ Gem::Specification.new do |s|
"lib/redis/set.rb",
"lib/redis/types.rb",
"lib/redis/value.rb",
+ "lib/redis/zset.rb",
"redis-types.gemspec",
"spec/dump.rdb",
"spec/redis/types_spec.rb",

0 comments on commit da9eaf7

Please sign in to comment.