Class: EntityCache::Controls::Store::External::Example
- Inherits:
-
Object
- Object
- EntityCache::Controls::Store::External::Example
- Includes:
- Store::External
- Defined in:
- lib/entity_cache/controls/store/external/example.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
- #configure(session: nil) ⇒ Object
- #get(id) ⇒ Object
- #path(id) ⇒ Object
- #put(id, entity, version, time) ⇒ Object
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
8 9 10 |
# File 'lib/entity_cache/controls/store/external/example.rb', line 8 def session @session end |
Instance Method Details
#configure(session: nil) ⇒ Object
10 11 12 |
# File 'lib/entity_cache/controls/store/external/example.rb', line 10 def configure(session: nil) self.session = session end |
#get(id) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/entity_cache/controls/store/external/example.rb', line 14 def get(id) path = path(id) return unless File.size?(path) text = File.read(path) entity_data, version, time_iso8601 = YAML.load(text) entity = Entity::Example.new( entity_data[:id], entity_data[:some_attr], entity_data[:other_attr] ) time = Clock.parse(time_iso8601) return entity, version, time end |
#path(id) ⇒ Object
46 47 48 |
# File 'lib/entity_cache/controls/store/external/example.rb', line 46 def path(id) External.path(subject, id) end |
#put(id, entity, version, time) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/entity_cache/controls/store/external/example.rb', line 34 def put(id, entity, version, time) path = path(id) entity_data = entity.to_h time_iso8601 = Clock.iso8601(time) text = YAML.dump([entity_data, version, time_iso8601]) File.write(path, text) end |