evt-entity_cache 2.0.0.0 → 2.0.1.1

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: 25e74b321dd2f21a4eee738fb03124e987869725c03943c0b94914b564cb9ea7
4
- data.tar.gz: d84fab0cf0251910d38a19ac2ca9b336962cee0007dc6058dbbe4fa3c29d146b
3
+ metadata.gz: 4ccf37e36c243d747764757e86a6552c649f157b1feabb174fd025d4019ecdff
4
+ data.tar.gz: 41ab27c85c699eacffd6cca4122eb44db0fa537a5ff033f73eca29ace4937f16
5
5
  SHA512:
6
- metadata.gz: 97c5fe39d6be68ed4238bf84a9c3016ac3dab76a45fb3ca457dd9f34389de248897d5c2f3080f40e49f3668aede6318a94e8e7e2428803cac292439b24a959d6
7
- data.tar.gz: 11328e53484c330cb2d66238d1adbcc6018e815bb6f3c47379d479844cafd10d0865b6241ae4adff49ebcc5d0690116ba7c9f4b5cb8098e8ccacc0daefb6914e
6
+ metadata.gz: 96bfc7773f4e5e34c307315c8de52e2741b933c9f75bc49e7d96f34df3ac5dd5e024b4c8964c12afc019cc1fd8fbd675ca3dae069b220751fee89a215f1a0c4e
7
+ data.tar.gz: eb9c2b7ace7f89be4c7fd035a8b405b4be8c01b058f22fd694b0de0398a83295d364185c7950ae3b2b194e358100e90179d168c34ce482b10da3bb5bd3ac481b
@@ -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,15 @@ 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 = YAML.load(text)
22
+
23
+ entity = Entity::Example.new(
24
+ entity_data[:id],
25
+ entity_data[:some_attr],
26
+ entity_data[:other_attr]
27
+ )
28
+
29
+ time = Clock.parse(time_iso8601)
22
30
 
23
31
  return entity, version, time
24
32
  end
@@ -26,7 +34,11 @@ class EntityCache
26
34
  def put(id, entity, version, time)
27
35
  path = path(id)
28
36
 
29
- text = YAML.dump([entity, version, time])
37
+ entity_data = entity.to_h
38
+
39
+ time_iso8601 = Clock.iso8601(time)
40
+
41
+ text = YAML.dump([entity_data, version, time_iso8601])
30
42
 
31
43
  File.write(path, text)
32
44
  end
@@ -39,7 +51,11 @@ class EntityCache
39
51
  def self.path(subject, id=nil)
40
52
  id ||= ID.example
41
53
 
42
- File.join(tmpdir, "#{subject}-#{id}.yaml")
54
+ filename = "#{subject.to_s.gsub('/', '-')}-#{id}.yaml"
55
+
56
+ full_name = File.join(tmpdir, filename)
57
+
58
+ full_name
43
59
  end
44
60
 
45
61
  def self.tmpdir
@@ -6,10 +6,14 @@ class EntityCache
6
6
  def self.call
7
7
  subject = Subject.example
8
8
 
9
+ entity_data = Controls::Entity.example.to_h
10
+
11
+ persisted_time_iso8601 = Controls::Record.persisted_time.iso8601(5)
12
+
9
13
  text = YAML.dump([
10
- Controls::Entity.example,
14
+ entity_data,
11
15
  Controls::Record.persisted_version,
12
- Controls::Record.persisted_time
16
+ persisted_time_iso8601
13
17
  ])
14
18
 
15
19
  path = External.path(subject)
@@ -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
@@ -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.0
4
+ version: 2.0.1.1
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: 2019-12-10 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,13 +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
- - lib/loader.rb
123
125
  homepage: https://github.com/eventide-project/entity-cache
124
126
  licenses:
125
127
  - MIT
126
128
  metadata: {}
127
- post_install_message:
129
+ post_install_message:
128
130
  rdoc_options: []
129
131
  require_paths:
130
132
  - lib
@@ -139,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
- rubygems_version: 3.0.1
143
- signing_key:
144
+ rubygems_version: 3.3.3
145
+ signing_key:
144
146
  specification_version: 4
145
147
  summary: Cache of entities retrieved by an entity-store, with in-memory temporary
146
148
  and on-disk permanent storage options
data/lib/loader.rb DELETED
@@ -1 +0,0 @@
1
- lib/entity_cache.rb