Class: Gloo::Persist::PersistMan
- Inherits:
-
Object
- Object
- Gloo::Persist::PersistMan
- Defined in:
- lib/gloo/persist/persist_man.rb
Instance Attribute Summary collapse
-
#maps ⇒ Object
readonly
Returns the value of attribute maps.
-
#mech ⇒ Object
readonly
Returns the value of attribute mech.
Instance Method Summary collapse
-
#file_ext ⇒ Object
Get the default file extention.
-
#find_file_storage(obj) ⇒ Object
Find the objects FileStorage in the list.
-
#get_full_path_names(name) ⇒ Object
Get the full path and name of the file.
-
#gloo_file?(name) ⇒ Boolean
Check to see if a given path name refers to a gloo object file.
-
#initialize(engine) ⇒ PersistMan
constructor
Contructor for the persistence manager.
-
#load(name) ⇒ Object
Load the object from the file.
-
#reload(obj) ⇒ Object
Re-load the given object from file.
-
#reload_all ⇒ Object
Reload all objects.
-
#save(name = '') ⇒ Object
Save one object to the file.
-
#save_all ⇒ Object
Save one object to the file.
-
#save_one(name) ⇒ Object
Save one object to the file.
-
#show_maps ⇒ Object
Print out all object - persistance mappings.
-
#unload(obj) ⇒ Object
The given object is unloading.
-
#unload_all ⇒ Object
Unload all loaded objects.
Constructor Details
#initialize(engine) ⇒ PersistMan
Contructor for the persistence manager.
18 19 20 21 22 |
# File 'lib/gloo/persist/persist_man.rb', line 18 def initialize( engine ) @engine = engine @maps = [] @mech = @engine.platform.getFileMech( @engine ) end |
Instance Attribute Details
#maps ⇒ Object (readonly)
Returns the value of attribute maps.
13 14 15 |
# File 'lib/gloo/persist/persist_man.rb', line 13 def maps @maps end |
#mech ⇒ Object (readonly)
Returns the value of attribute mech.
13 14 15 |
# File 'lib/gloo/persist/persist_man.rb', line 13 def mech @mech end |
Instance Method Details
#file_ext ⇒ Object
Get the default file extention.
152 153 154 |
# File 'lib/gloo/persist/persist_man.rb', line 152 def file_ext return @mech.file_ext end |
#find_file_storage(obj) ⇒ Object
Find the objects FileStorage in the list.
119 120 121 122 123 124 125 126 |
# File 'lib/gloo/persist/persist_man.rb', line 119 def find_file_storage( obj ) @maps.each do |o| return o if ( o.obj.pn === obj.pn ) end # It was not found, so return nil. return nil end |
#get_full_path_names(name) ⇒ Object
Get the full path and name of the file.
132 133 134 135 136 137 138 139 140 |
# File 'lib/gloo/persist/persist_man.rb', line 132 def get_full_path_names( name ) return nil if name.strip.empty? if name.strip[ -1 ] == '*' return @mech.get_all_files_in( name[ 0..-2 ] ) else return @mech.( name ) end end |
#gloo_file?(name) ⇒ Boolean
Check to see if a given path name refers to a gloo object file.
145 146 147 |
# File 'lib/gloo/persist/persist_man.rb', line 145 def gloo_file?( name ) return @mech.valid?( name ) end |
#load(name) ⇒ Object
Load the object from the file.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gloo/persist/persist_man.rb', line 55 def load( name ) pns = get_full_path_names name return unless pns pns.each do |pn| @engine.log.debug "Load file(s) at: #{pn}" fs = Gloo::Persist::FileStorage.new( @engine, pn ) fs.load @maps << fs @engine.event_manager.on_load fs.obj end end |
#reload(obj) ⇒ Object
Re-load the given object from file.
107 108 109 110 111 112 113 114 |
# File 'lib/gloo/persist/persist_man.rb', line 107 def reload( obj ) fs = find_file_storage( obj ) return unless fs @engine.event_manager.on_reload obj @engine.heap.unload obj fs.load end |
#reload_all ⇒ Object
Reload all objects.
94 95 96 97 98 99 100 101 102 |
# File 'lib/gloo/persist/persist_man.rb', line 94 def reload_all return unless @maps @maps.each do |fs| @engine.event_manager.on_reload fs.obj @engine.heap.unload fs.obj fs.load end end |
#save(name = '') ⇒ Object
Save one object to the file.
27 28 29 |
# File 'lib/gloo/persist/persist_man.rb', line 27 def save( name = '' ) name.blank? ? save_all : save_one( name ) end |
#save_all ⇒ Object
Save one object to the file.
34 35 36 |
# File 'lib/gloo/persist/persist_man.rb', line 34 def save_all @maps.each( &:save ) end |
#save_one(name) ⇒ Object
Save one object to the file.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gloo/persist/persist_man.rb', line 41 def save_one( name ) ref = Gloo::Core::Pn.new( @engine, name ) obj = ref.resolve # Send an on_save event @engine.event_manager.on_save obj fs = find_file_storage( obj ) fs.save end |
#show_maps ⇒ Object
Print out all object - persistance mappings. This is a debugging tool.
160 161 162 163 164 |
# File 'lib/gloo/persist/persist_man.rb', line 160 def show_maps @maps.each do |o| puts " \t #{o.pn} \t #{o.obj.name}" end end |
#unload(obj) ⇒ Object
The given object is unloading. Do any necessary clean up here.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gloo/persist/persist_man.rb', line 80 def unload( obj ) @engine.event_manager.on_unload obj @engine.heap.unload obj @maps.each_with_index do |o, i| if o.obj.pn === obj.pn @maps.delete_at( i ) return end end end |
#unload_all ⇒ Object
Unload all loaded objects.
71 72 73 74 |
# File 'lib/gloo/persist/persist_man.rb', line 71 def unload_all objs = self.maps.map { |fs| fs.obj } objs.each { |o| o.msg_unload } end |