Module: Seabright::Dumping

Included in:
RedisObject
Defined in:
lib/redis_object/experimental/dumping.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



90
91
92
# File 'lib/redis_object/experimental/dumping.rb', line 90

def self.included(base)
	base.extend(ClassMethods)
end

Instance Method Details

#dump_collectionsObject



66
67
68
69
70
71
72
73
# File 'lib/redis_object/experimental/dumping.rb', line 66

def dump_collections
	cols = []
	collections.inject({}) do |acc,(k,v)|
		acc[k.to_sym] = v.map {|o| o.hkey }
		cols << k
		acc
	end.merge(collections: cols)
end

#full_hash_dumpObject

def dump(file=nil) if file && File.exists?(file) # else self.to_yaml end end



62
63
64
# File 'lib/redis_object/experimental/dumping.rb', line 62

def full_hash_dump
	store.hgetall(hkey).inject({}) {|acc,(k,v)| acc[k.to_sym] = enforce_format(k,v); acc }.merge(dump_collections)
end

#to_jsonObject



75
76
77
# File 'lib/redis_object/experimental/dumping.rb', line 75

def to_json
	Yajl::Encoder.encode(full_hash_dump)
end

#to_yamlObject Also known as: to_yml



79
80
81
# File 'lib/redis_object/experimental/dumping.rb', line 79

def to_yaml
	Psych.dump(full_hash_dump)
end