Module: Persistence::Object::Flat::File::ObjectInstance

Includes:
FilePersistence
Included in:
Persistence::Object::Flat::File
Defined in:
lib/persistence/object/flat/file/object_instance.rb

Overview

Instance 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

#persistence_hash_to_portHash

Generate hash representing object.

Returns:

  • (Hash)

    Hash representing information to reproduce object instance.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/persistence/object/flat/file/object_instance.rb', line 20

def persistence_hash_to_port

  persistence_contents = nil

  # if we are persisting by file path
  if persists_files_by_path?
    persistence_contents = ::Persistence::Object::Flat::File::Path.new( path )
  # if we are persisting by file contents
  else
    starting_pos = self.pos
    persistence_contents = ::Persistence::Object::Flat::File::Contents.new( self.readlines.join )
    # rewind file to wherever we started
    self.pos = starting_pos
  end

  primary_key = persistence_bucket.primary_key_for_attribute_name( self, self.class.to_s )

  return { primary_key => persistence_contents }

end

#persists_file_paths_as_strings?Boolean

persists_file_paths_as_strings? #

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/persistence/object/flat/file/object_instance.rb', line 81

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 = self.class.persists_file_paths_as_strings?
  end
  
  return persists_file_paths_as_strings
  
end

#persists_files_by_content?Boolean

persists_files_by_content? #

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/persistence/object/flat/file/object_instance.rb', line 45

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 = self.class.persists_files_by_content?
  end
  
  return persists_files_by_content
  
end

#persists_files_by_path?Boolean

persists_files_by_path? #

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/persistence/object/flat/file/object_instance.rb', line 63

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 = self.class.persists_files_by_path?
  end
  
  return persists_files_by_path
  
end