evt-entity_cache 2.0.0.1 → 2.0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0007333aebd8a09e10abc3015998b795d8f30dedeb7a68bbad6346654eb0a70a
4
- data.tar.gz: c7a3b0a1b774b6936b6c37bf28cb9aa80763c3a896963a4ccacd6694aa577b04
3
+ metadata.gz: 0a65dee7e03fdffdece4718fe1d50e5cdf3f5e59466dfb224068b84c8356b6fc
4
+ data.tar.gz: b5f966733c02ad8280f954d10226ae99656788514d522e66e3b7750b1670ed62
5
5
  SHA512:
6
- metadata.gz: 240bda1f074aa169d17ba8aa867598c78e14adbe9c4ce851c4a290a157e8057b6f4bc22bd8bfe95e6779b1d53eda1d23b01f9f14f28c8f61c3c66048282531b8
7
- data.tar.gz: 214fb735d89e7fcee4ef7289401db0295fb59c9cb2100631f4de44a2b5d985b23d1903a6dbec1d4911f8407b53e8490be2556cd18ce95a3d6570e0f221f020a5
6
+ metadata.gz: bad5d326c349c724b90b47fc8e4c5bfbf9c6558be071d9a61b1363266284a084b4a4ff2e5cde5eeb9596570252927e7cbb8038e610f3d9d5d4229e4232384072
7
+ data.tar.gz: fc18bafad76966151ff5029c4af0996e1b763113efc50a47e7f740f2c94b5030fc58bbe0fac5e8a73617e4014f20ea65bcba755e754d9762e26302541c02b827
@@ -0,0 +1,11 @@
1
+ class EntityCache
2
+ module Controls
3
+ module EntityCache
4
+ def self.example(subject=nil, entity_class: nil, specifier: nil, random_specifier: nil)
5
+ subject ||= Subject.example(entity_class: entity_class, specifier: specifier, random: random_specifier)
6
+
7
+ ::EntityCache.new(subject)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -15,7 +15,7 @@ class EntityCache
15
15
  persisted_time ||= self.persisted_time
16
16
  end
17
17
 
18
- EntityCache::Record.new(
18
+ ::EntityCache::Record.new(
19
19
  id,
20
20
  entity,
21
21
  version,
@@ -0,0 +1,16 @@
1
+ class EntityCache
2
+ module Controls
3
+ module Specifier
4
+ def self.example(specifier: nil, random: nil)
5
+ specifier ||= 'SomeSpecifier'
6
+ random ||= false
7
+
8
+ if random
9
+ specifier = "#{specifier}#{SecureRandom.hex(8)}"
10
+ end
11
+
12
+ specifier
13
+ end
14
+ end
15
+ end
16
+ end
@@ -18,7 +18,11 @@ class EntityCache
18
18
 
19
19
  text = File.read(path)
20
20
 
21
- entity, version, time = YAML.load(text)
21
+ entity_data, version, time_iso8601 = JSON.parse(text, symbolize_names: true)
22
+
23
+ entity = Entity::Example.new(*entity_data)
24
+
25
+ time = Clock.parse(time_iso8601)
22
26
 
23
27
  return entity, version, time
24
28
  end
@@ -26,7 +30,17 @@ class EntityCache
26
30
  def put(id, entity, version, time)
27
31
  path = path(id)
28
32
 
29
- text = YAML.dump([entity, version, time])
33
+ entity_data = Transform::Write.raw_data(entity)
34
+
35
+ time_iso8601 = Clock.iso8601(time)
36
+
37
+ data = [
38
+ entity_data,
39
+ version,
40
+ time_iso8601
41
+ ]
42
+
43
+ text = JSON.generate(data)
30
44
 
31
45
  File.write(path, text)
32
46
  end
@@ -39,7 +53,11 @@ class EntityCache
39
53
  def self.path(subject, id=nil)
40
54
  id ||= ID.example
41
55
 
42
- File.join(tmpdir, "#{subject}-#{id}.yaml")
56
+ filename = "#{subject.to_s.gsub('/', '-')}-#{id}.yaml"
57
+
58
+ full_name = File.join(tmpdir, filename)
59
+
60
+ full_name
43
61
  end
44
62
 
45
63
  def self.tmpdir
@@ -6,11 +6,18 @@ class EntityCache
6
6
  def self.call
7
7
  subject = Subject.example
8
8
 
9
- text = YAML.dump([
10
- Controls::Entity.example,
9
+ entity = Controls::Entity.example
10
+ entity_data = Transform::Write.raw_data(entity)
11
+
12
+ persisted_time_iso8601 = Controls::Record.persisted_time.iso8601(5)
13
+
14
+ data = [
15
+ entity_data,
11
16
  Controls::Record.persisted_version,
12
- Controls::Record.persisted_time
13
- ])
17
+ persisted_time_iso8601
18
+ ]
19
+
20
+ text = JSON.generate(data)
14
21
 
15
22
  path = External.path(subject)
16
23
 
@@ -2,8 +2,10 @@ class EntityCache
2
2
  module Controls
3
3
  module Store
4
4
  module External
5
- def self.example(subject=nil)
6
- subject ||= Subject.example
5
+ def self.example(subject=nil, entity_class: nil, specifier: nil, random: nil)
6
+ random = true if random.nil?
7
+
8
+ subject ||= Subject.example(random: random, entity_class: entity_class, specifier: specifier)
7
9
 
8
10
  Example.build(subject)
9
11
  end
@@ -1,8 +1,34 @@
1
1
  class EntityCache
2
2
  module Controls
3
3
  module Subject
4
- def self.example
5
- "some-subject-#{SecureRandom.hex(7)}"
4
+ def self.example(entity_class: nil, specifier: nil, random: nil)
5
+ entity_class ||= self.entity_class
6
+
7
+ if specifier == :none
8
+ specifier = nil
9
+ else
10
+ specifier = Specifier.example(specifier: specifier, random: random)
11
+ end
12
+
13
+ ::EntityCache::Subject.build({
14
+ :entity_class => entity_class,
15
+ :specifier => specifier
16
+ })
17
+ end
18
+
19
+ def self.entity_class
20
+ Entity::Example
21
+ end
22
+
23
+ def self.specifier
24
+ Specifier.example
25
+ end
26
+
27
+ module HashKey
28
+ def self.example(**args)
29
+ subject = Subject.example(**args)
30
+ subject.hash_key
31
+ end
6
32
  end
7
33
  end
8
34
  end
@@ -1,4 +1,4 @@
1
- require 'yaml'
1
+ require 'json'
2
2
  require 'tmpdir'
3
3
 
4
4
  require 'clock/controls'
@@ -11,6 +11,8 @@ require 'entity_cache/controls/subject'
11
11
  require 'entity_cache/controls/time'
12
12
  require 'entity_cache/controls/version'
13
13
 
14
+ require 'entity_cache/controls/specifier'
15
+
14
16
  require 'entity_cache/controls/persist_interval'
15
17
 
16
18
  require 'entity_cache/controls/store/external'
@@ -19,3 +21,5 @@ require 'entity_cache/controls/store/external/not_implemented'
19
21
  require 'entity_cache/controls/store/external/write'
20
22
 
21
23
  require 'entity_cache/controls/store/internal'
24
+
25
+ require 'entity_cache/controls/entity_cache'
@@ -1,6 +1,7 @@
1
1
  class EntityCache
2
2
  include Configure
3
3
  include Dependency
4
+ include Initializer
4
5
  include Log::Dependency
5
6
 
6
7
  configure :entity_cache
@@ -10,12 +11,27 @@ class EntityCache
10
11
  @persist_interval ||= Defaults.persist_interval
11
12
  end
12
13
 
14
+ def entity_class
15
+ subject.entity_class
16
+ end
17
+
18
+ def specifier
19
+ subject.specifier
20
+ end
21
+
13
22
  dependency :clock, Clock::UTC
14
23
  dependency :internal_store, Store::Internal
15
24
  dependency :external_store, Store::External
16
25
 
17
- def self.build(subject, scope: nil, persist_interval: nil, external_store: nil, external_store_session: nil)
18
- instance = new
26
+ initializer :subject
27
+
28
+ def self.build(entity_class, specifier=nil, scope: nil, persist_interval: nil, external_store: nil, external_store_session: nil)
29
+ subject = Subject.build({
30
+ :entity_class => entity_class,
31
+ :specifier => specifier
32
+ })
33
+
34
+ instance = new(subject)
19
35
 
20
36
  instance.configure(
21
37
  subject: subject,
@@ -30,6 +30,14 @@ class EntityCache
30
30
  end
31
31
  end
32
32
 
33
+ def entity_class
34
+ subject.entity_class
35
+ end
36
+
37
+ def specifier
38
+ subject.specifier
39
+ end
40
+
33
41
  module Configure
34
42
  def configure(session: nil)
35
43
  ::Telemetry.configure(self)
@@ -0,0 +1,29 @@
1
+ class EntityCache
2
+ class Subject
3
+ include Schema::DataStructure
4
+
5
+ attribute :entity_class, Class
6
+ attribute :specifier, String
7
+
8
+ def hash_key
9
+ self.class.hash_key(entity_class, specifier)
10
+ end
11
+ alias_method :to_s, :hash_key
12
+
13
+ def hash
14
+ hash_key.hash
15
+ end
16
+
17
+ def self.hash_key(entity_class, specifier=nil)
18
+ if specifier.nil?
19
+ "#{entity_class}"
20
+ else
21
+ "#{entity_class}#{hash_key_separator}#{specifier}"
22
+ end
23
+ end
24
+
25
+ def self.hash_key_separator
26
+ '/'
27
+ end
28
+ end
29
+ end
@@ -5,6 +5,9 @@ class EntityCache
5
5
  end
6
6
 
7
7
  class EntityCache < EntityCache
8
+ def initialize
9
+ end
10
+
8
11
  def self.build
9
12
  new
10
13
  end
data/lib/entity_cache.rb CHANGED
@@ -7,6 +7,8 @@ require 'entity_cache/log'
7
7
 
8
8
  require 'entity_cache/defaults'
9
9
 
10
+ require 'entity_cache/subject'
11
+
10
12
  require 'entity_cache/record'
11
13
  require 'entity_cache/record/destructure'
12
14
  require 'entity_cache/record/log_text'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-entity_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.1
4
+ version: 2.0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-configure
@@ -89,9 +89,11 @@ files:
89
89
  - lib/entity_cache.rb
90
90
  - lib/entity_cache/controls.rb
91
91
  - lib/entity_cache/controls/entity.rb
92
+ - lib/entity_cache/controls/entity_cache.rb
92
93
  - lib/entity_cache/controls/id.rb
93
94
  - lib/entity_cache/controls/persist_interval.rb
94
95
  - lib/entity_cache/controls/record.rb
96
+ - lib/entity_cache/controls/specifier.rb
95
97
  - lib/entity_cache/controls/store/external.rb
96
98
  - lib/entity_cache/controls/store/external/example.rb
97
99
  - lib/entity_cache/controls/store/external/not_implemented.rb
@@ -118,12 +120,13 @@ files:
118
120
  - lib/entity_cache/store/internal/scope/global.rb
119
121
  - lib/entity_cache/store/internal/scope/thread.rb
120
122
  - lib/entity_cache/store/internal/substitute.rb
123
+ - lib/entity_cache/subject.rb
121
124
  - lib/entity_cache/substitute.rb
122
125
  homepage: https://github.com/eventide-project/entity-cache
123
126
  licenses:
124
127
  - MIT
125
128
  metadata: {}
126
- post_install_message:
129
+ post_install_message:
127
130
  rdoc_options: []
128
131
  require_paths:
129
132
  - lib
@@ -138,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
141
  - !ruby/object:Gem::Version
139
142
  version: '0'
140
143
  requirements: []
141
- rubygems_version: 3.0.1
142
- signing_key:
144
+ rubygems_version: 3.3.4
145
+ signing_key:
143
146
  specification_version: 4
144
147
  summary: Cache of entities retrieved by an entity-store, with in-memory temporary
145
148
  and on-disk permanent storage options