lib/redis/base_object.rb in redis-objects-1.2.1 vs lib/redis/base_object.rb in redis-objects-1.3.0

- old
+ new

@@ -25,7 +25,21 @@ def allow_expiration(&block) result = block.call set_expiration result end + + def to_json(*args) + to_hash.to_json(*args) + rescue NoMethodError => e + raise e.class, "The current runtime does not provide a `to_json` implementation. Require 'json' or another JSON library and try again." + end + + def as_json(*) + to_hash + end + + def to_hash + { "key" => @key, "options" => @options, "value" => value } + end end end