Class: ResoTransport::MetadataCache

Inherits:
Object
  • Object
show all
Defined in:
lib/reso_transport/metadata_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ MetadataCache

Returns a new instance of MetadataCache.



5
6
7
# File 'lib/reso_transport/metadata_cache.rb', line 5

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/reso_transport/metadata_cache.rb', line 3

def name
  @name
end

Instance Method Details

#readObject



9
10
11
12
13
# File 'lib/reso_transport/metadata_cache.rb', line 9

def read
  return nil if !File.exist?(name) || File.size(name).zero?

  File.new(name)
end

#write(raw) ⇒ Object



15
16
17
18
# File 'lib/reso_transport/metadata_cache.rb', line 15

def write(raw)
  File.open(name, 'w') { |f| f.write(raw.force_encoding('UTF-8')) } if raw.length.positive?
  File.new(name)
end