Module: Persistence::Object::Flat::File::ClassInstance

Includes:
FilePersistence
Defined in:
lib/persistence/object/flat/file/class_instance.rb

Overview

Class methods for File objects enabled with persistence capabilities.

Instance Method Summary collapse

Methods included from FilePersistence

#persist_files_by_content!, #persist_files_by_path!

Instance Method Details

#persist(*args) ⇒ Object

persist #



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/persistence/object/flat/file/class_instance.rb', line 13

def persist( *args )

  persistence_value = nil

  index_instance, key, no_key = parse_class_args_for_index_value_no_value( args )

  # if no key, open a cursor for a list
  if no_key

    persistence_value = ::Persistence::Cursor.new( instance_persistence_bucket, index_instance )

  else

    if global_id = index_instance ? index_instance.get_object_id( key ) : key
    
      persistence_value_hash = instance_persistence_bucket.get_object_hash( global_id )
    
      persistence_value = persistence_value_hash.first[ 1 ]
    
      if persistence_value.is_a?( ::Persistence::Object::Flat::File::Path ) and
         ! persists_file_paths_as_strings?

        persistence_value = open( persistence_value, persistence_value.mode || 'r' )

      end

    end
    
  end
  
  return persistence_value

end

#persists_file_paths_as_strings?true, false

Query whether File paths should be persisted as strings (rather than by objects).

Lookup chain is: File instance, File class, Persistence::Port::Bucket instance, Persistence::Port instance,
Persistence singleton.

Returns:

  • (true, false)

    Whether files should be persisted as strings rather than as objects.



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/persistence/object/flat/file/class_instance.rb', line 101

def persists_file_paths_as_strings?
  
  persists_file_paths_as_strings = nil
  
  persists_file_paths_as_strings = super
  
  if persists_file_paths_as_strings.nil?
    persists_file_paths_as_strings = instance_persistence_bucket.persists_file_paths_as_strings?
  end
  
  return persists_file_paths_as_strings
  
end

#persists_files_by_content?Boolean

persists_files_by_content? #

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/persistence/object/flat/file/class_instance.rb', line 51

def persists_files_by_content?
  
  persists_files_by_content = nil
  
  persists_files_by_content = super
  
  if persists_files_by_content.nil?
    persists_files_by_content = instance_persistence_bucket.persists_files_by_content?
  end
  
  return persists_files_by_content
  
end

#persists_files_by_path?true, false

Query whether File instances should be persisted by path (rather than by content).

Lookup chain is: File instance, File class, Persistence::Port::Bucket instance, Persistence::Port instance,
Persistence singleton.

Returns:

  • (true, false)

    Whether files should be persisted by path rather than by content.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/persistence/object/flat/file/class_instance.rb', line 76

def persists_files_by_path?
  
  persists_files_by_path = nil
  
  persists_files_by_path = super
  
  if persists_files_by_path.nil?
    persists_files_by_path = instance_persistence_bucket.persists_files_by_path?
  end
  
  return persists_files_by_path
  
end