key-vortex 0.1.4 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ef4caa4048de91fa4f99f928fd154c9ae3950a971fb6d8ad34149070f900914
4
- data.tar.gz: 179229a1dd86d3e31fa2dca1d43089ab11000625a5260c5aaf8c31c7a691f3c8
3
+ metadata.gz: f43cf073bdd351c00643d8efadeca2cb832cba972ca21fdeb2cd8e7f96e0b305
4
+ data.tar.gz: 121850a5e65071c2b1b7d88a00768c2768c815c94b9bde9adacaf86468b78b35
5
5
  SHA512:
6
- metadata.gz: 7c847153af457304066f16e28436a018f289e73b1a929811e506c83d5bfb1da3d45be68a89b6c3781207dd11481753cfd9ec6b95335da58c6a88fc072d65546f
7
- data.tar.gz: cfddc7282c2775b03595c679a3369c61584069b2cb961eeb68194ecb9d62fa1c204602611a1be473c410271648bcb3f7fe4b6b8230dacd874e3b2daea66a119a
6
+ metadata.gz: f3674b7796e65a5cc6f01a0b51c53a960fc52d4502438cf184b5cbd977b234a68b404225545f5d4dac8b2ca64acffe396556fc6a2ef96e3741ee329b0b88461a
7
+ data.tar.gz: 51505756b9515790e6b8a5071ceb6fc2db46ab6890e6a22118e6dccd2e28b44bd4876ca7317f6ab08ed4c6ad6884f2ac6cdab3098c283006ab3bfa58ff6da50a
data/.reek.yml CHANGED
@@ -2,3 +2,8 @@ detectors:
2
2
  # TODO: Remove once design is set
3
3
  IrresponsibleModule:
4
4
  enabled: false
5
+
6
+ DuplicateMethodCall:
7
+ exclude:
8
+ - KeyVortex::Record#self.define_getter
9
+ - KeyVortex::Record#self.define_setter
data/.rubocop.yml CHANGED
@@ -16,3 +16,8 @@ Layout/LineLength:
16
16
  # TODO: Remove once design is set
17
17
  Style/Documentation:
18
18
  Enabled: false
19
+
20
+ Metrics/BlockLength:
21
+ AllowedMethods:
22
+ - describe
23
+ - context
data/Gemfile CHANGED
@@ -17,6 +17,6 @@ gem "guard-rspec"
17
17
  gem "guard-rubocop"
18
18
 
19
19
  gem "byebug"
20
- gem "stashify-contract"
20
+ gem "key_vortex-contract"
21
21
 
22
22
  gem "yard"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- key-vortex (0.1.4)
4
+ key-vortex (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,6 +33,7 @@ GEM
33
33
  guard (~> 2.0)
34
34
  rubocop (< 2.0)
35
35
  json (2.6.3)
36
+ key_vortex-contract (0.2.0)
36
37
  kwalify (0.7.2)
37
38
  listen (3.8.0)
38
39
  rb-fsevent (~> 0.10, >= 0.10.3)
@@ -51,7 +52,6 @@ GEM
51
52
  method_source (~> 1.0)
52
53
  rainbow (3.1.1)
53
54
  rake (13.0.6)
54
- rantly (2.0.0)
55
55
  rb-fsevent (0.11.2)
56
56
  rb-inotify (0.10.1)
57
57
  ffi (~> 1.0)
@@ -88,9 +88,6 @@ GEM
88
88
  parser (>= 3.2.1.0)
89
89
  ruby-progressbar (1.13.0)
90
90
  shellany (0.0.1)
91
- stashify-contract (1.0.1)
92
- rantly (~> 2.0.0)
93
- rspec (~> 3.0)
94
91
  thor (1.2.2)
95
92
  unicode-display_width (2.4.2)
96
93
  yard (0.9.34)
@@ -105,11 +102,11 @@ DEPENDENCIES
105
102
  guard-rspec
106
103
  guard-rubocop
107
104
  key-vortex!
105
+ key_vortex-contract
108
106
  rake (~> 13.0)
109
107
  reek (~> 6.1.4)
110
108
  rspec (~> 3.0)
111
109
  rubocop (~> 1.21)
112
- stashify-contract
113
110
  yard
114
111
 
115
112
  BUNDLED WITH
@@ -12,7 +12,7 @@ class KeyVortex
12
12
  end
13
13
 
14
14
  def save(record)
15
- @items[record.id] = record
15
+ @items[record.key] = record
16
16
  end
17
17
 
18
18
  def find(id)
@@ -12,7 +12,7 @@ class KeyVortex
12
12
  end
13
13
 
14
14
  def to_s
15
- "#{attribute}: #{value}"
15
+ "#{attribute}: #{limit}"
16
16
  end
17
17
  end
18
18
  end
@@ -5,11 +5,11 @@ require "key_vortex/constraint/base"
5
5
  class KeyVortex
6
6
  class Constraint
7
7
  class Length < KeyVortex::Constraint::Base
8
- attr_reader :value
8
+ attr_reader :limit
9
9
 
10
- def initialize(value)
10
+ def initialize(limit)
11
11
  super()
12
- @value = value
12
+ @limit = limit
13
13
  end
14
14
 
15
15
  def attribute
@@ -17,7 +17,11 @@ class KeyVortex
17
17
  end
18
18
 
19
19
  def within?(constraint)
20
- super && value <= constraint.value
20
+ super && limit <= constraint.limit
21
+ end
22
+
23
+ def accepts?(value)
24
+ value.length <= limit
21
25
  end
22
26
  end
23
27
  end
@@ -5,11 +5,11 @@ require "key_vortex/constraint/base"
5
5
  class KeyVortex
6
6
  class Constraint
7
7
  class Maximum < KeyVortex::Constraint::Base
8
- attr_reader :value
8
+ attr_reader :limit
9
9
 
10
- def initialize(value)
10
+ def initialize(limit)
11
11
  super()
12
- @value = value
12
+ @limit = limit
13
13
  end
14
14
 
15
15
  def attribute
@@ -17,7 +17,11 @@ class KeyVortex
17
17
  end
18
18
 
19
19
  def within?(constraint)
20
- super && value <= constraint.value
20
+ super && limit <= constraint.limit
21
+ end
22
+
23
+ def accepts?(value)
24
+ value <= limit
21
25
  end
22
26
  end
23
27
  end
@@ -5,11 +5,11 @@ require "key_vortex/constraint/base"
5
5
  class KeyVortex
6
6
  class Constraint
7
7
  class Minimum < KeyVortex::Constraint::Base
8
- attr_reader :value
8
+ attr_reader :limit
9
9
 
10
- def initialize(value)
10
+ def initialize(limit)
11
11
  super()
12
- @value = value
12
+ @limit = limit
13
13
  end
14
14
 
15
15
  def attribute
@@ -17,7 +17,11 @@ class KeyVortex
17
17
  end
18
18
 
19
19
  def within?(constraint)
20
- super && value >= constraint.value
20
+ super && limit >= constraint.limit
21
+ end
22
+
23
+ def accepts?(value)
24
+ value >= limit
21
25
  end
22
26
  end
23
27
  end
@@ -17,9 +17,13 @@ class KeyVortex
17
17
  end)
18
18
  end
19
19
 
20
- def prohibited_by?(adapter)
20
+ def within?(adapter)
21
21
  limitation = adapter.limitation_for(self)
22
- limitation&.prohibits?(self.limitation)
22
+ !limitation || self.limitation.within?(limitation)
23
+ end
24
+
25
+ def accepts?(value)
26
+ limitation.accepts?(value)
23
27
  end
24
28
  end
25
29
  end
@@ -20,28 +20,40 @@ class KeyVortex
20
20
  @constraints += constraints
21
21
  end
22
22
 
23
- def allows?(limitation)
23
+ def encompasses?(limitation)
24
24
  @constraints.all? do |constraint|
25
- limitation.accomodates?(constraint)
25
+ limitation.encompasses_constraint?(constraint)
26
26
  end
27
27
  end
28
28
 
29
- def prohibits?(limitation)
30
- !allows?(limitation)
29
+ def encompasses_constraint?(constraint)
30
+ !applicable_constraints(constraint).select do |con|
31
+ con.within?(constraint)
32
+ end.empty?
31
33
  end
32
34
 
33
- def applicable_constraints(constraint)
34
- @constraints.select do |con|
35
- con.applies_to?(constraint)
35
+ def within?(limitation)
36
+ limitation.constraints.all? do |constraint|
37
+ within_constraint?(constraint)
36
38
  end
37
39
  end
38
40
 
39
- def accomodates?(constraint)
41
+ def within_constraint?(constraint)
40
42
  !applicable_constraints(constraint).select do |con|
41
43
  con.within?(constraint)
42
44
  end.empty?
43
45
  end
44
46
 
47
+ def applicable_constraints(constraint)
48
+ @constraints.select do |con|
49
+ con.applies_to?(constraint)
50
+ end
51
+ end
52
+
53
+ def accepts?(value)
54
+ value.is_a?(type) && @constraints.all? { |constraint| constraint.accepts?(value) }
55
+ end
56
+
45
57
  def to_s
46
58
  "Limitation: #{@type}\n\t#{@constraints.join('\n\t')}"
47
59
  end
@@ -19,8 +19,26 @@ class KeyVortex
19
19
  register_field(KeyVortex::Field.new(name, type, **constraints_hash))
20
20
  end
21
21
 
22
+ def self.field_constraints(field)
23
+ @field_hash[field]
24
+ end
25
+
22
26
  def self.register_field(field)
23
27
  field_hash[field.name] = field
28
+ define_getter(field)
29
+ define_setter(field)
30
+ end
31
+
32
+ def self.define_getter(field)
33
+ define_method(field.name) { @values[field.name] }
34
+ end
35
+
36
+ def self.define_setter(field)
37
+ define_method("#{field.name}=") do |val|
38
+ raise KeyVortex::Error, "Invalid value #{val} for #{field.name}" unless field.accepts?(val)
39
+
40
+ @values[field.name] = val
41
+ end
24
42
  end
25
43
 
26
44
  def self.inherited(subclass)
@@ -33,20 +51,17 @@ class KeyVortex
33
51
  # Long enough to accomodate a GUID
34
52
  field :key, String, length: 36
35
53
 
36
- def initialize(fields)
37
- @field_hash = fields
38
- end
39
-
40
- def respond_to_missing?(method, *args)
41
- args.empty? && self.class.field_constraints(method)
42
- end
54
+ attr_reader :values
43
55
 
44
- def method_missing(method, *_args)
45
- @field_hash[method]
56
+ def initialize(values = {})
57
+ @values = {}
58
+ values.each do |name, value|
59
+ send("#{name}=", value)
60
+ end
46
61
  end
47
62
 
48
- def self.field_constraints(field)
49
- @field_hash[field]
63
+ def ==(other)
64
+ self.class == other.class && values == other.values
50
65
  end
51
66
  end
52
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class KeyVortex
4
- VERSION = "0.1.4"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/key_vortex.rb CHANGED
@@ -10,7 +10,7 @@ class KeyVortex
10
10
  @record_class = record_class
11
11
 
12
12
  record_class.fields.each do |field|
13
- next unless field.prohibited_by?(adapter)
13
+ next if field.within?(adapter)
14
14
 
15
15
  raise KeyVortex::Error,
16
16
  "#{adapter.class} can only handle field #{field.name} with these limitations:\n" +
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key-vortex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lambda Null
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-09 00:00:00.000000000 Z
11
+ date: 2023-07-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Defines abstractions that can be built on top of for key/value storage
14
14
  on different technologies (file, s3, sql, redis, etc.)