Class: EntityCache::Controls::Store::External::Example

Inherits:
Object
  • Object
show all
Includes:
Store::External
Defined in:
lib/entity_cache/controls/store/external/example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sessionObject

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
# 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 = JSON.parse(text, symbolize_names: true)

  entity = Entity::Example.new(*entity_data)

  time = Clock.parse(time_iso8601)

  return entity, version, time
end

#path(id) ⇒ Object



50
51
52
# File 'lib/entity_cache/controls/store/external/example.rb', line 50

def path(id)
  External.path(subject, id)
end

#put(id, entity, version, time) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/entity_cache/controls/store/external/example.rb', line 30

def put(id, entity, version, time)
  path = path(id)

  entity_data = Transform::Write.raw_data(entity)

  time_iso8601 = Clock.iso8601(time)

  data = [
    entity_data,
    version,
    time_iso8601
  ]

  text = JSON.generate(data)

  FileUtils.mkdir_p(External.file_dump_directory)

  File.write(path, text)
end