evt-entity_cache 0.11.1.4 → 0.12.0.0

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
  SHA1:
3
- metadata.gz: 8251a924a2a0fab71cbeeeb09e651b8231335d71
4
- data.tar.gz: 0a05cb3cf74ba601b61ec88343e654091dfe84cb
3
+ metadata.gz: 9c13e158e958cbdf1b17b702403a04cab1e97b9e
4
+ data.tar.gz: c87287bf2c2dd8c6b4c8497f422e3d0de3dc04de
5
5
  SHA512:
6
- metadata.gz: a85c0f48909c09d4eadd9535ddacd6b648d2d08c9569073468b51ce7bfc531eae2046d5342cff525195d1d8f9bf4ae391b6800aebe1746b34d6090a6b2ee5ced
7
- data.tar.gz: bc692f1803e63b642f3a87ccbfa54838d262005ed647cf4cf51ce0a9f4fc80fe689a19d41524cf5c42a9881635e6a41410c439a0770c8d82ef9667e5a46a1f94
6
+ metadata.gz: 376f814a1a462177be63978ad21dcb44a4c411982ec80a9f7272b2b7f19e38489a62930705840ffbfbe92445ed047943aa7984ae1adc12f4e83b0402dc194af3
7
+ data.tar.gz: b5e0b438bd336036fb33b4edf8a51781b92789bb84f7d9ebc11f69164247fe84cbd558ec99e053323e5c8cc2eee934b4eb7e153948627bfd4df21565c78e1cdd
data/lib/entity_cache.rb CHANGED
@@ -6,6 +6,8 @@ require 'virtual'; Virtual.activate
6
6
 
7
7
  require 'entity_cache/log'
8
8
 
9
+ require 'entity_cache/error'
10
+
9
11
  require 'entity_cache/record'
10
12
 
11
13
  require 'entity_cache/storage/persistent'
@@ -14,7 +16,7 @@ require 'entity_cache/storage/persistent/substitute'
14
16
  require 'entity_cache/storage/persistent/telemetry'
15
17
 
16
18
  require 'entity_cache/storage/temporary'
17
- require 'entity_cache/storage/temporary/factory'
19
+ require 'entity_cache/storage/temporary/build'
18
20
  require 'entity_cache/storage/temporary/scope'
19
21
  require 'entity_cache/storage/temporary/scope/exclusive'
20
22
  require 'entity_cache/storage/temporary/scope/shared'
@@ -6,6 +6,7 @@ require 'entity_cache/controls/entity'
6
6
  require 'entity_cache/controls/record'
7
7
  require 'entity_cache/controls/storage/persistent'
8
8
  require 'entity_cache/controls/storage/temporary'
9
+ require 'entity_cache/controls/subject'
9
10
  require 'entity_cache/controls/time'
10
11
  require 'entity_cache/controls/version'
11
12
  require 'entity_cache/controls/persist_interval'
@@ -10,14 +10,21 @@ class EntityCache
10
10
  time = Time.example
11
11
  persisted_time = time
12
12
 
13
- EntityCache::Record.new id, entity, version, time, persisted_version, persisted_time
13
+ EntityCache::Record.new(
14
+ id,
15
+ entity,
16
+ version,
17
+ time,
18
+ persisted_version,
19
+ persisted_time
20
+ )
14
21
  end
15
22
 
16
23
  module Persisted
17
24
  def self.example(id=nil)
18
25
  version = Version::Persistent.example
19
26
 
20
- Record.example id, version: version
27
+ Record.example(id, version: version)
21
28
  end
22
29
  end
23
30
  end
@@ -27,11 +27,13 @@ class EntityCache
27
27
  end
28
28
 
29
29
  def self.example
30
- Example.build :some_subject
30
+ subject = Subject.example
31
+
32
+ Example.build(subject)
31
33
  end
32
34
 
33
35
  def self.substitute
34
- SubstAttr::Substitute.build Example
36
+ SubstAttr::Substitute.build(Example)
35
37
  end
36
38
  end
37
39
  end
@@ -3,7 +3,9 @@ class EntityCache
3
3
  module Storage
4
4
  module Temporary
5
5
  def self.example
6
- EntityCache::Storage::Temporary::Scope::Exclusive.build :some_subject
6
+ subject = Subject.example
7
+
8
+ EntityCache::Storage::Temporary::Scope::Exclusive.build(subject)
7
9
  end
8
10
  end
9
11
  end
@@ -0,0 +1,11 @@
1
+ class EntityCache
2
+ module Controls
3
+ module Subject
4
+ def self.example(random: nil)
5
+ random = true if random.nil?
6
+
7
+ "TestSubject#{SecureRandom.hex(7) if random}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,12 +1,15 @@
1
1
  class EntityCache
2
2
  module Controls
3
- Time = Clock::Controls::Time
4
-
5
3
  module Time
4
+ include Clock::Controls::Time
5
+
6
6
  def self.example(time=nil, precision: nil)
7
- time ||= Raw.example
8
7
  precision ||= 5
9
- ISO8601.example(time, precision: precision)
8
+
9
+ Clock::Controls::Time.example(
10
+ time=nil,
11
+ precision: precision
12
+ )
10
13
  end
11
14
  end
12
15
  end
@@ -1,6 +1,4 @@
1
1
  class EntityCache
2
- Error = Class.new(RuntimeError)
3
-
4
2
  include Log::Dependency
5
3
 
6
4
  configure :cache
@@ -11,7 +9,7 @@ class EntityCache
11
9
  dependency :persistent_store, Storage::Persistent
12
10
  dependency :temporary_store, Storage::Temporary
13
11
 
14
- def self.build(subject, persistent_store: nil, persist_interval: nil, session: nil)
12
+ def self.build(subject, scope: nil, persistent_store: nil, persist_interval: nil, session: nil)
15
13
  unless persistent_store.nil? == persist_interval.nil?
16
14
  raise Error, "Must specify both the persistent store and persist interval, or neither"
17
15
  end
@@ -22,7 +20,7 @@ class EntityCache
22
20
  instance.persist_interval = persist_interval
23
21
 
24
22
  Clock::UTC.configure instance
25
- Storage::Temporary.configure instance, subject
23
+ Storage::Temporary.configure(instance, subject, scope: scope)
26
24
 
27
25
  persistent_store.configure(instance, subject, session: session)
28
26
 
@@ -48,18 +46,16 @@ class EntityCache
48
46
  def put(id, entity, version, persisted_version=nil, persisted_time=nil, time: nil)
49
47
  time ||= clock.iso8601(precision: 5)
50
48
 
51
- logger.trace { "Writing cache (ID: #{id}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time}, Persistent Version: #{persisted_version.inspect}, Persistent Time: #{persisted_time.inspect})" }
52
-
53
- record = Record.new id, entity, version, time, persisted_version, persisted_time
54
-
55
- put_record record
49
+ record = Record.new(id, entity, version, time, persisted_version, persisted_time)
56
50
 
57
- logger.info { "Cache written (ID: #{id}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time}, Persistent Version: #{persisted_version.inspect}, Persistent Time: #{persisted_time.inspect})" }
51
+ put_record(record)
58
52
 
59
53
  record
60
54
  end
61
55
 
62
56
  def put_record(record)
57
+ logger.trace { "Writing cache (ID: #{record.id}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time}, Persistent Version: #{record.persisted_version.inspect}, Persistent Time: #{record.persisted_time.inspect})" }
58
+
63
59
  if persist_interval && record.versions_since_persisted >= persist_interval
64
60
  persisted_time = clock.iso8601(precision: 5)
65
61
 
@@ -69,17 +65,19 @@ class EntityCache
69
65
  record.persisted_time = persisted_time
70
66
  end
71
67
 
68
+ logger.info { "Cache written (ID: #{record.id}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time}, Persistent Version: #{record.persisted_version.inspect}, Persistent Time: #{record.persisted_time.inspect})" }
69
+
72
70
  temporary_store.put record
73
71
  end
74
72
 
75
73
  def restore(id)
76
- entity, persisted_version, persisted_time = persistent_store.get id
74
+ entity, persisted_version, persisted_time = persistent_store.get(id)
77
75
 
78
76
  return nil if entity.nil?
79
77
 
80
78
  version = persisted_version
81
79
  time = persisted_time
82
80
 
83
- put id, entity, version, persisted_version, persisted_time, time: time
81
+ put(id, entity, version, persisted_version, persisted_time, time: time)
84
82
  end
85
83
  end
@@ -0,0 +1,3 @@
1
+ class EntityCache
2
+ Error = Class.new(RuntimeError)
3
+ end
@@ -1,5 +1,5 @@
1
1
  class EntityCache
2
- class Record < Struct.new :id, :entity, :version, :time, :persisted_version, :persisted_time
2
+ class Record < Struct.new(:id, :entity, :version, :time, :persisted_version, :persisted_time)
3
3
  def versions_since_persisted
4
4
  persisted_version = self.persisted_version
5
5
  persisted_version ||= -1
@@ -17,7 +17,9 @@ class EntityCache
17
17
  includes.each do |attribute|
18
18
  value = public_send attribute
19
19
 
20
- value = NoStream.version if value.nil? && attribute == :version
20
+ if value.nil? && attribute == :version
21
+ value = NoStream.version
22
+ end
21
23
 
22
24
  responses << value
23
25
  end
@@ -32,7 +34,7 @@ class EntityCache
32
34
  module NoStream
33
35
  def self.destructure(includes=nil)
34
36
  record = Record.new
35
- record.destructure includes
37
+ record.destructure(includes)
36
38
  end
37
39
 
38
40
  def self.version
@@ -17,7 +17,7 @@ class EntityCache
17
17
  def self.configure(receiver, subject, scope: nil, attr_name: nil)
18
18
  attr_name ||= :temporary_store
19
19
 
20
- instance = Factory.(subject, scope: scope)
20
+ instance = Build.(subject, scope: scope)
21
21
  receiver.public_send "#{attr_name}=", instance
22
22
  instance
23
23
  end
@@ -1,7 +1,7 @@
1
1
  class EntityCache
2
2
  module Storage
3
3
  class Temporary
4
- module Factory
4
+ module Build
5
5
  def self.call(subject, scope: nil)
6
6
  scope ||= Scope::Defaults::Name.get
7
7
 
@@ -17,9 +17,9 @@ class EntityCache
17
17
 
18
18
  time = clock.iso8601(precision: 5)
19
19
 
20
- record = Record.new id, entity, version, time, persisted_version, time
20
+ record = Record.new(id, entity, version, time, persisted_version, time)
21
21
 
22
- temporary_store.put record
22
+ temporary_store.put(record)
23
23
  end
24
24
 
25
25
  def put_record(record)
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: 0.11.1.4
4
+ version: 0.12.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2017-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-configure
@@ -136,10 +136,12 @@ files:
136
136
  - lib/entity_cache/controls/record.rb
137
137
  - lib/entity_cache/controls/storage/persistent.rb
138
138
  - lib/entity_cache/controls/storage/temporary.rb
139
+ - lib/entity_cache/controls/subject.rb
139
140
  - lib/entity_cache/controls/time.rb
140
141
  - lib/entity_cache/controls/version.rb
141
142
  - lib/entity_cache/defaults.rb
142
143
  - lib/entity_cache/entity_cache.rb
144
+ - lib/entity_cache/error.rb
143
145
  - lib/entity_cache/log.rb
144
146
  - lib/entity_cache/record.rb
145
147
  - lib/entity_cache/storage/persistent.rb
@@ -147,12 +149,11 @@ files:
147
149
  - lib/entity_cache/storage/persistent/substitute.rb
148
150
  - lib/entity_cache/storage/persistent/telemetry.rb
149
151
  - lib/entity_cache/storage/temporary.rb
150
- - lib/entity_cache/storage/temporary/factory.rb
152
+ - lib/entity_cache/storage/temporary/build.rb
151
153
  - lib/entity_cache/storage/temporary/scope.rb
152
154
  - lib/entity_cache/storage/temporary/scope/exclusive.rb
153
155
  - lib/entity_cache/storage/temporary/scope/shared.rb
154
156
  - lib/entity_cache/substitute.rb
155
- - lib/loader.rb
156
157
  homepage: https://github.com/eventide-project/entity-cache
157
158
  licenses:
158
159
  - MIT
@@ -165,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
166
  requirements:
166
167
  - - ">="
167
168
  - !ruby/object:Gem::Version
168
- version: 2.3.3
169
+ version: 2.4.0
169
170
  required_rubygems_version: !ruby/object:Gem::Requirement
170
171
  requirements:
171
172
  - - ">="
data/lib/loader.rb DELETED
@@ -1 +0,0 @@
1
- lib/entity_cache.rb