Class: Rets::Metadata::Caching
- Inherits:
-
Object
- Object
- Rets::Metadata::Caching
- Defined in:
- lib/rets/metadata/caching.rb
Overview
Metadata caching.
Instance Attribute Summary collapse
- #cache ⇒ Object readonly
- #serializer ⇒ Object readonly
Class Method Summary collapse
-
.make(options) ⇒ Object
Given the options passed to Client#initialize, make an instance.
Instance Method Summary collapse
-
#initialize(cache, serializer) ⇒ Caching
constructor
The cache is responsible for reading and writing the serialized metadata.
-
#load(logger) ⇒ Object
Load metadata.
-
#save(metadata) ⇒ Object
Save metadata.
Constructor Details
#initialize(cache, serializer) ⇒ Caching
The cache is responsible for reading and writing the serialized metadata. The cache should quack like a Rets::Metadata::FileCache.
The serializer is responsible for serializing/deserializing the metadata. The serializer should quack like a Rets::Metadata::MarshalSerializer.
34 35 36 37 |
# File 'lib/rets/metadata/caching.rb', line 34 def initialize(cache, serializer) @cache = cache @serializer = serializer end |
Instance Attribute Details
#cache ⇒ Object (readonly)
24 25 26 |
# File 'lib/rets/metadata/caching.rb', line 24 def cache @cache end |
#serializer ⇒ Object (readonly)
25 26 27 |
# File 'lib/rets/metadata/caching.rb', line 25 def serializer @serializer end |
Class Method Details
.make(options) ⇒ Object
Given the options passed to Client#initialize, make an instance. Options:
-
:metadata_cache - Persistence mechanism. Defaults to NullCache.
-
“metadata_serializer - Serialization mechanism. Defaults to MarshalSerializer.
16 17 18 19 20 21 22 |
# File 'lib/rets/metadata/caching.rb', line 16 def self.make() cache = .fetch(:metadata_cache) { Metadata::NullCache.new } serializer = .fetch(:metadata_serializer) do Metadata::MarshalSerializer.new end new(cache, serializer) end |
Instance Method Details
#load(logger) ⇒ Object
Load metadata. Returns a Metadata::Root if successful, or nil if it could be loaded for any reason.
41 42 43 44 45 46 47 |
# File 'lib/rets/metadata/caching.rb', line 41 def load(logger) sources = @cache.load do |file| @serializer.load(file) end return nil unless sources.is_a?(Hash) Metadata::Root.new(logger, sources) end |
#save(metadata) ⇒ Object
Save metadata.
50 51 52 53 54 |
# File 'lib/rets/metadata/caching.rb', line 50 def save() @cache.save do |file| @serializer.save(file, .sources) end end |