Class: Seabright::RedisObject

Inherits:
Object
  • Object
show all
Includes:
Benchmark, CachedScripts, Collections, DefaultValues, Dumping, Filters, Indices, InheritanceTracking, Keys, Matchers, ObjectBase, Storage, Timestamps, Triggers, Types, ViewCaching, Views
Defined in:
lib/redis_object.rb,
lib/redis_object/indices.rb,
lib/redis_object/version.rb,
lib/redis_object/ext/script_cache.rb,
lib/redis_object/experimental/dumping.rb

Defined Under Namespace

Modules: ScriptSources

Constant Summary collapse

VERSION =
"1.5.3"

Constants included from ViewCaching

ViewCaching::CachedViewInvalidator

Constants included from Views

Views::ViewFieldGetter

Class Method Summary collapse

Methods included from Dumping

#dump_collections, format_dump, #full_hash_dump, included, #to_json, #to_yaml

Methods included from Benchmark

included

Methods included from Timestamps

included, #update_timestamps

Methods included from ViewCaching

included

Methods included from Views

included, #view_as_hash, #view_as_json

Methods included from Triggers

included

Methods included from Types

alias_type, #enforce_format, included, known_types, register_type, #save_format, #score_format, type_aliases, #type_filter_for

Methods included from Collections

#<<, #backreferences, #collect_type_by_key, #collection_name, #collection_names, #collections, #delete_child, #dereference_from, #dereference_from_backreferences, #get_collection, #has_collection?, #hkey_col, included, #load, #push, #ref_key, #reference, #referenced_by, #remove_collection!

Methods included from Indices

included, #index_key

Methods included from DefaultValues

included

Methods included from Keys

#hkey, included, #key, #ref_field_key, #reserve_key

Methods included from Storage

included, #store

Methods included from CachedScripts

included, #run_script

Methods included from InheritanceTracking

included

Methods included from Matchers

included

Methods included from ObjectBase

#[], #[]=, #_get, #clean_id, #define_setter_getter, #delete!, #dereference_all!, #filter_gotten_value, #generate_id, #get, #get_reference, #id, #initialize, #is_ref_key?, #is_set?, #load, #mset, #new_id, #raw, #reserve, #save, #set, #set_ref, #setnx, #track_ref_key, #undefine_setter_getter, #unset

Methods included from Filters

included

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Seabright::ObjectBase

Class Method Details

.constant_lookupsObject



3
4
5
# File 'lib/redis_object/inheritance_tracking.rb', line 3

def RedisObject.constant_lookups
	@constant_lookups ||= {}
end

.dump_everything(dump_format = :hash) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/redis_object/experimental/dumping.rb', line 7

def self.dump_everything(dump_format=:hash)
	out = {}
	ObjectSpace.enum_for(:each_object, class << RedisObject; self; end).each do |cls|
		unless cls == RedisObject
			out.merge! cls.dump_all(:hash)
		end
	end
	Dumping.format_dump out, dump_format
end

.load_data(dat) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/redis_object/experimental/dumping.rb', line 31

def self.load_data(dat)
	dat.each do |(k,v)|
		if klass = RedisObject.deep_const_get(k)
			if v[:objects]
				v[:objects].each do |o|
					load_object klass, o
				end
			end
		end
	end
end

.load_dump(str, dump_format = :hash) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/redis_object/experimental/dumping.rb', line 17

def self.load_dump(str,dump_format=:hash)
	case dump_format
	when :hash
		load_dump_from_hash str
	when :yaml, :yml
		load_dump_from_yaml str
	# JSON format is not ready yet!
	# when :json
	# 	load_dump_from_json str
	else
		raise "Unknown dump format."
	end
end

.load_dump_from_hash(str) ⇒ Object



47
48
49
# File 'lib/redis_object/experimental/dumping.rb', line 47

def self.load_dump_from_hash(str)
	load_data str
end

.load_dump_from_yaml(str) ⇒ Object



43
44
45
# File 'lib/redis_object/experimental/dumping.rb', line 43

def self.load_dump_from_yaml(str)
	load_data Psych.load(str)
end

.load_object(klass, pkt) ⇒ Object

JSON format is not ready yet! def self.load_dump_from_json(str) load_data Yajl::Parser.new(symbolize_keys: true).parse(str) end



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/redis_object/experimental/dumping.rb', line 56

def self.load_object(klass,pkt)
	Log.debug "Loading a #{klass.name}: #{pkt.inspect}"
	cols = nil
	pkt.delete(:collections).each do |col_name|
		if objs = pkt.delete(col_name.to_sym)
			cols ||= {}
			cols[col_name.to_sym] = objs
		end
	end
	obj = klass.create(pkt)
	if cols
		cols.each do |name,objs|
			Log.debug "  Loading in collected #{name}: #{objs.inspect}"
			obj.collect_type_by_key name, *objs
		end
	end
end

.reindex_everything!Object



5
6
7
8
9
# File 'lib/redis_object/indices.rb', line 5

def self.reindex_everything!
	RedisObject.child_classes.each do |cls|
		cls.reindex_all_indices!
	end
end