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.
Instance Method Summary collapse
-
#file_ext ⇒ Object
Get the default file extention.
-
#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 ⇒ PersistMan
constructor
Contructor for the persistence manager.
-
#load(name) ⇒ Object
Load the object from the file.
-
#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.
Constructor Details
#initialize ⇒ PersistMan
Contructor for the persistence manager.
18 19 20 |
# File 'lib/gloo/persist/persist_man.rb', line 18 def initialize @maps = [] 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 |
Instance Method Details
#file_ext ⇒ Object
Get the default file extention.
104 105 106 |
# File 'lib/gloo/persist/persist_man.rb', line 104 def file_ext return '.gloo' end |
#get_full_path_names(name) ⇒ Object
Get the full path and name of the file.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/gloo/persist/persist_man.rb', line 70 def get_full_path_names( name ) return nil if name.strip.empty? if name.strip[ -1 ] == '*' pns = [] dir = File.join( $settings.project_path, name[ 0..-2 ] ) Dir.glob( "#{dir}*.gloo" ).each do |f| pns << f end return pns else ext_path = File.( name ) return [ ext_path ] if self.gloo_file?( ext_path ) full_name = "#{name}#{file_ext}" return [ File.join( $settings.project_path, full_name ) ] end end |
#gloo_file?(name) ⇒ Boolean
Check to see if a given path name refers to a gloo object file.
92 93 94 95 96 97 98 99 |
# File 'lib/gloo/persist/persist_man.rb', line 92 def gloo_file?( name ) return false unless name return false unless File.exist?( name ) return false unless File.file?( name ) return false unless name.end_with?( self.file_ext ) return true end |
#load(name) ⇒ Object
Load the object from the file.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gloo/persist/persist_man.rb', line 54 def load( name ) pns = get_full_path_names name return unless pns pns.each do |pn| $log.debug "Load file(s) at: #{pn}" fs = Gloo::Persist::FileStorage.new( pn ) fs.load @maps << fs $engine.event_manager.on_load fs.obj end end |
#save(name = '') ⇒ Object
Save one object to the file.
25 26 27 28 29 30 31 |
# File 'lib/gloo/persist/persist_man.rb', line 25 def save( name = '' ) if name.nil? || name.strip.empty? save_all else save_one name end end |
#save_all ⇒ Object
Save one object to the file.
36 37 38 |
# File 'lib/gloo/persist/persist_man.rb', line 36 def save_all @maps.each( &:save ) end |
#save_one(name) ⇒ Object
Save one object to the file.
43 44 45 46 47 48 49 |
# File 'lib/gloo/persist/persist_man.rb', line 43 def save_one( name ) ref = Gloo::Core::Pn.new name obj = ref.resolve pn = get_full_path_name name fs = Gloo::Persist::FileStorage.new( pn, obj ) fs.save end |
#show_maps ⇒ Object
Print out all object - persistance mappings. This is a debugging tool.
112 113 114 115 116 |
# File 'lib/gloo/persist/persist_man.rb', line 112 def show_maps @maps.each do |o| puts " \t #{o.pn} \t #{o.obj.name}" end end |