evt-entity_cache 0.13.0.0 → 0.14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/entity_cache.rb +17 -15
  3. data/lib/entity_cache/controls.rb +12 -3
  4. data/lib/entity_cache/controls/entity.rb +27 -1
  5. data/lib/entity_cache/controls/persist_interval.rb +2 -22
  6. data/lib/entity_cache/controls/record.rb +33 -12
  7. data/lib/entity_cache/controls/storage/persistent.rb +8 -26
  8. data/lib/entity_cache/controls/storage/persistent/example.rb +41 -0
  9. data/lib/entity_cache/controls/storage/persistent/not_implemented.rb +19 -0
  10. data/lib/entity_cache/controls/storage/persistent/write.rb +25 -0
  11. data/lib/entity_cache/controls/storage/temporary.rb +14 -2
  12. data/lib/entity_cache/controls/subject.rb +2 -4
  13. data/lib/entity_cache/controls/time.rb +1 -12
  14. data/lib/entity_cache/controls/version.rb +5 -11
  15. data/lib/entity_cache/defaults.rb +2 -2
  16. data/lib/entity_cache/record.rb +36 -30
  17. data/lib/entity_cache/record/destructure.rb +29 -0
  18. data/lib/entity_cache/record/log_text.rb +9 -0
  19. data/lib/entity_cache/record/transformer.rb +26 -0
  20. data/lib/entity_cache/store/persistent/null.rb +15 -0
  21. data/lib/entity_cache/store/persistent/substitute.rb +64 -0
  22. data/lib/entity_cache/store/persistent/telemetry.rb +16 -0
  23. data/lib/entity_cache/store/temporary.rb +47 -0
  24. data/lib/entity_cache/store/temporary/build.rb +48 -0
  25. data/lib/entity_cache/store/temporary/build/defaults.rb +28 -0
  26. data/lib/entity_cache/{storage → store}/temporary/scope/exclusive.rb +1 -1
  27. data/lib/entity_cache/store/temporary/scope/global.rb +34 -0
  28. data/lib/entity_cache/store/temporary/scope/thread.rb +35 -0
  29. data/lib/entity_cache/store/temporary/substitute.rb +36 -0
  30. data/lib/entity_cache/substitute.rb +33 -17
  31. metadata +20 -58
  32. data/lib/entity_cache/entity_cache.rb +0 -83
  33. data/lib/entity_cache/error.rb +0 -3
  34. data/lib/entity_cache/storage/persistent.rb +0 -81
  35. data/lib/entity_cache/storage/persistent/none.rb +0 -15
  36. data/lib/entity_cache/storage/persistent/substitute.rb +0 -51
  37. data/lib/entity_cache/storage/persistent/telemetry.rb +0 -38
  38. data/lib/entity_cache/storage/temporary.rb +0 -56
  39. data/lib/entity_cache/storage/temporary/build.rb +0 -42
  40. data/lib/entity_cache/storage/temporary/scope/defaults.rb +0 -32
  41. data/lib/entity_cache/storage/temporary/scope/error.rb +0 -9
  42. data/lib/entity_cache/storage/temporary/scope/shared.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c760e8d0f0ab3b57d038d2611c3e79d5e5f226cb
4
- data.tar.gz: 744488e69439058ff3f775a98f17b93c1551a06e
3
+ metadata.gz: 60ce778606243f14d742f85711593dbf6fe226ec
4
+ data.tar.gz: eadfeebaaac7e8477278e938eaa90e8328d1d307
5
5
  SHA512:
6
- metadata.gz: '07090ee107dc4cbe58dffcf6e9d96e492e40507b0dc4db5fe7dc85f4cbbdecfdb31a2b25f473eb8d217f0383351fac3600d827c0a4f8cdabeba26e5fc661ef04'
7
- data.tar.gz: 1bbcfc1b53dfa8411446b5df243418eda16014b91c3977f37fa8e037354012dd88cd99384bfac9d7232af4dd35f282c5cdd38f25443e7d3a28028026a651be2c
6
+ metadata.gz: 5d77d5302fac329c64b7642d2553a0dbdc0e470aa1744b1922fd6f06102dd33bd64a67c911a0ddcf49360e6eaa2072f02ccfd307353ed55d22751c56840bc124
7
+ data.tar.gz: 0af5181fd7d7998c0d46972163ed1f3859b3c9f25ff5d64b35a72dbe1724374f4cd34584473521ef397ba4d9350a2a36aca03d73ae33b1dad0193fbc3a09af35
@@ -1,27 +1,29 @@
1
1
  require 'configure'; Configure.activate
2
- require 'settings'; Settings.activate
2
+ require 'message_store'
3
+ require 'settings'
3
4
  require 'telemetry'
4
- require 'log'
5
- require 'virtual'; Virtual.activate
6
5
 
7
6
  require 'entity_cache/log'
8
7
 
9
- require 'entity_cache/error'
8
+ require 'entity_cache/defaults'
10
9
 
11
10
  require 'entity_cache/record'
11
+ require 'entity_cache/record/destructure'
12
+ require 'entity_cache/record/log_text'
13
+ require 'entity_cache/record/transformer'
12
14
 
13
- require 'entity_cache/storage/persistent'
14
- require 'entity_cache/storage/persistent/none'
15
- require 'entity_cache/storage/persistent/substitute'
16
- require 'entity_cache/storage/persistent/telemetry'
15
+ require 'entity_cache/store/persistent'
16
+ require 'entity_cache/store/persistent/null'
17
+ require 'entity_cache/store/persistent/substitute'
18
+ require 'entity_cache/store/persistent/telemetry'
17
19
 
18
- require 'entity_cache/storage/temporary'
19
- require 'entity_cache/storage/temporary/build'
20
- require 'entity_cache/storage/temporary/scope/defaults'
21
- require 'entity_cache/storage/temporary/scope/error'
22
- require 'entity_cache/storage/temporary/scope/exclusive'
23
- require 'entity_cache/storage/temporary/scope/shared'
20
+ require 'entity_cache/store/temporary'
21
+ require 'entity_cache/store/temporary/build'
22
+ require 'entity_cache/store/temporary/build/defaults'
23
+ require 'entity_cache/store/temporary/scope/exclusive'
24
+ require 'entity_cache/store/temporary/scope/global'
25
+ require 'entity_cache/store/temporary/scope/thread'
26
+ require 'entity_cache/store/temporary/substitute'
24
27
 
25
- require 'entity_cache/defaults'
26
28
  require 'entity_cache/entity_cache'
27
29
  require 'entity_cache/substitute'
@@ -1,12 +1,21 @@
1
+ require 'yaml'
2
+ require 'tmpdir'
3
+
1
4
  require 'clock/controls'
2
5
  require 'identifier/uuid/controls'
3
6
 
4
- require 'entity_cache/controls/id'
5
7
  require 'entity_cache/controls/entity'
8
+ require 'entity_cache/controls/id'
6
9
  require 'entity_cache/controls/record'
7
- require 'entity_cache/controls/storage/persistent'
8
- require 'entity_cache/controls/storage/temporary'
9
10
  require 'entity_cache/controls/subject'
10
11
  require 'entity_cache/controls/time'
11
12
  require 'entity_cache/controls/version'
13
+
12
14
  require 'entity_cache/controls/persist_interval'
15
+
16
+ require 'entity_cache/controls/storage/persistent'
17
+ require 'entity_cache/controls/storage/persistent/example'
18
+ require 'entity_cache/controls/storage/persistent/not_implemented'
19
+ require 'entity_cache/controls/storage/persistent/write'
20
+
21
+ require 'entity_cache/controls/storage/temporary'
@@ -2,7 +2,33 @@ class EntityCache
2
2
  module Controls
3
3
  module Entity
4
4
  def self.example
5
- Object.new
5
+ Example.new(id, some_attr, other_attr)
6
+ end
7
+
8
+ def self.id
9
+ ID.example
10
+ end
11
+
12
+ def self.some_attr
13
+ 'some-value'
14
+ end
15
+
16
+ def self.other_attr
17
+ 'other-value'
18
+ end
19
+
20
+ Example = Struct.new(:id, :some_attr, :other_attr)
21
+
22
+ class Example
23
+ module Transformer
24
+ def self.raw_data(instance)
25
+ instance.to_a
26
+ end
27
+
28
+ def self.instance(raw_data)
29
+ Example.new(*raw_data)
30
+ end
31
+ end
6
32
  end
7
33
  end
8
34
  end
@@ -1,28 +1,8 @@
1
1
  class EntityCache
2
2
  module Controls
3
3
  module PersistInterval
4
- module Exceeds
5
- def self.example
6
- Version.example - Version::Persistent.example
7
- end
8
-
9
- module NoStream
10
- def self.example
11
- Version.example
12
- end
13
- end
14
- end
15
-
16
- module Within
17
- def self.example
18
- Exceeds.example + 1
19
- end
20
-
21
- module NoStream
22
- def self.example
23
- Exceeds::NoStream.example + 1
24
- end
25
- end
4
+ def self.example
5
+ 11
26
6
  end
27
7
  end
28
8
  end
@@ -1,14 +1,19 @@
1
1
  class EntityCache
2
2
  module Controls
3
3
  module Record
4
- def self.example(id=nil, version: nil, persisted_version: nil)
5
- id ||= ID.example
6
- entity = Entity.example
7
- version ||= Version.example
8
- persisted_version ||= Version::Persistent.example
4
+ def self.example(entity=nil, id: nil, version: nil, time: nil, persisted: nil, persisted_version: nil, persisted_time: nil)
5
+ entity ||= self.entity
6
+ id ||= self.id
7
+ version ||= self.version
8
+ time ||= self.time
9
9
 
10
- time = Time.example
11
- persisted_time = time
10
+ unless persisted == false
11
+ persisted_version ||= self.persisted_version
12
+ end
13
+
14
+ unless persisted == false
15
+ persisted_time ||= self.persisted_time
16
+ end
12
17
 
13
18
  EntityCache::Record.new(
14
19
  id,
@@ -20,12 +25,28 @@ class EntityCache
20
25
  )
21
26
  end
22
27
 
23
- module Persisted
24
- def self.example(id=nil)
25
- version = Version::Persistent.example
28
+ def self.id
29
+ Entity.id
30
+ end
26
31
 
27
- Record.example(id, version: version)
28
- end
32
+ def self.entity
33
+ Entity.example
34
+ end
35
+
36
+ def self.time
37
+ Time::Offset::Raw.example(11)
38
+ end
39
+
40
+ def self.version
41
+ Version::Current.example
42
+ end
43
+
44
+ def self.persisted_time
45
+ Time::Offset::Raw.example(1)
46
+ end
47
+
48
+ def self.persisted_version
49
+ Version::Previous.example
29
50
  end
30
51
  end
31
52
  end
@@ -2,38 +2,20 @@ class EntityCache
2
2
  module Controls
3
3
  module Storage
4
4
  module Persistent
5
- class Example
6
- include EntityCache::Storage::Persistent
5
+ def self.example(subject=nil)
6
+ subject ||= Subject.example
7
7
 
8
- def get(id)
9
- entity, version, time = records[id]
10
-
11
- return entity, version, time
12
- end
13
-
14
- def put(id, entity, version, time)
15
- records[id] = [entity, version, time]
16
- end
17
-
18
- def records
19
- @records ||= {}
20
- end
21
-
22
- module Assertions
23
- def stored?(id, entity, version, time)
24
- records[id] == [entity, version, time]
25
- end
26
- end
8
+ Example.build(subject)
27
9
  end
28
10
 
29
- def self.example
30
- subject = Subject.example
11
+ def self.path(subject, id=nil)
12
+ id ||= ID.example
31
13
 
32
- Example.build(subject)
14
+ File.join(tmpdir, "#{subject}-#{id}.yaml")
33
15
  end
34
16
 
35
- def self.substitute
36
- SubstAttr::Substitute.build(Example)
17
+ def self.tmpdir
18
+ @tmpdir ||= Dir.tmpdir
37
19
  end
38
20
  end
39
21
  end
@@ -0,0 +1,41 @@
1
+ class EntityCache
2
+ module Controls
3
+ module Storage
4
+ module Persistent
5
+ class Example
6
+ include EntityCache::Store::Persistent
7
+
8
+ attr_accessor :session
9
+
10
+ def configure(session: nil)
11
+ self.session = session
12
+ end
13
+
14
+ def get(id)
15
+ path = path(id)
16
+
17
+ return unless File.size?(path)
18
+
19
+ text = File.read(path)
20
+
21
+ entity, version, time = YAML.load(text)
22
+
23
+ return entity, version, time
24
+ end
25
+
26
+ def put(id, entity, version, time)
27
+ path = path(id)
28
+
29
+ text = YAML.dump([entity, version, time])
30
+
31
+ File.write(path, text)
32
+ end
33
+
34
+ def path(id)
35
+ Persistent.path(subject, id)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ class EntityCache
2
+ module Controls
3
+ module Storage
4
+ module Persistent
5
+ module NotImplemented
6
+ def self.example
7
+ subject = Subject.example
8
+
9
+ Example.new(subject)
10
+ end
11
+
12
+ class Example
13
+ include EntityCache::Store::Persistent
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ class EntityCache
2
+ module Controls
3
+ module Storage
4
+ module Persistent
5
+ module Write
6
+ def self.call
7
+ subject = Subject.example
8
+
9
+ text = YAML.dump([
10
+ Controls::Entity.example,
11
+ Controls::Record.persisted_version,
12
+ Controls::Record.persisted_time
13
+ ])
14
+
15
+ path = Persistent.path(subject)
16
+
17
+ File.write(path, text)
18
+
19
+ return subject
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,9 +3,21 @@ class EntityCache
3
3
  module Storage
4
4
  module Temporary
5
5
  def self.example
6
- subject = Subject.example
6
+ Example.new
7
+ end
8
+
9
+ class Example < EntityCache::Store::Temporary
10
+ def records
11
+ @records ||= {}
12
+ end
7
13
 
8
- EntityCache::Storage::Temporary::Scope::Exclusive.build(subject)
14
+ def put?(id, record=nil)
15
+ if record.nil?
16
+ records.key?(id)
17
+ else
18
+ records[id] == record
19
+ end
20
+ end
9
21
  end
10
22
  end
11
23
  end
@@ -1,10 +1,8 @@
1
1
  class EntityCache
2
2
  module Controls
3
3
  module Subject
4
- def self.example(random: nil)
5
- random = true if random.nil?
6
-
7
- "TestSubject#{SecureRandom.hex(7) if random}"
4
+ def self.example
5
+ "some-subject-#{SecureRandom.hex(7)}"
8
6
  end
9
7
  end
10
8
  end
@@ -1,16 +1,5 @@
1
1
  class EntityCache
2
2
  module Controls
3
- module Time
4
- include Clock::Controls::Time
5
-
6
- def self.example(time=nil, precision: nil)
7
- precision ||= 5
8
-
9
- Clock::Controls::Time.example(
10
- time=nil,
11
- precision: precision
12
- )
13
- end
14
- end
3
+ Time = Clock::Controls::Time
15
4
  end
16
5
  end
@@ -2,24 +2,18 @@ class EntityCache
2
2
  module Controls
3
3
  module Version
4
4
  def self.example
5
- 11
5
+ Current.example
6
6
  end
7
7
 
8
- module SincePersisted
8
+ module Current
9
9
  def self.example
10
- Version.example - Persistent.example
10
+ 11
11
11
  end
12
12
  end
13
13
 
14
- module NoStream
14
+ module Previous
15
15
  def self.example
16
- EntityCache::Record::NoStream.version
17
- end
18
- end
19
-
20
- module Persistent
21
- def self.example
22
- 1
16
+ Current.example - 1
23
17
  end
24
18
  end
25
19
  end
@@ -1,7 +1,7 @@
1
1
  class EntityCache
2
2
  module Defaults
3
- def self.persistent_store
4
- Storage::Persistent::None
3
+ def self.persist_interval
4
+ Float::INFINITY
5
5
  end
6
6
  end
7
7
  end