key-vortex 0.2.1 → 0.2.3

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: f43cf073bdd351c00643d8efadeca2cb832cba972ca21fdeb2cd8e7f96e0b305
4
- data.tar.gz: 121850a5e65071c2b1b7d88a00768c2768c815c94b9bde9adacaf86468b78b35
3
+ metadata.gz: 5f5d707741ec015d0e2b2550267246b8d59ba9adf324cdbfd2502a81aedecfa1
4
+ data.tar.gz: f852c54e10c99863649639ab7974e81a93dc91403969d9cfaabd35ff068bdc67
5
5
  SHA512:
6
- metadata.gz: f3674b7796e65a5cc6f01a0b51c53a960fc52d4502438cf184b5cbd977b234a68b404225545f5d4dac8b2ca64acffe396556fc6a2ef96e3741ee329b0b88461a
7
- data.tar.gz: 51505756b9515790e6b8a5071ceb6fc2db46ab6890e6a22118e6dccd2e28b44bd4876ca7317f6ab08ed4c6ad6884f2ac6cdab3098c283006ab3bfa58ff6da50a
6
+ metadata.gz: c2d55b7eadf96acaacab4e9b81b52042c5809716d3536a76768c387f72353190a3ba15c38aded87b7ab6af357f0e8402fb8a8169b7f08271ca1e7ead84cae6f5
7
+ data.tar.gz: b8e30dca290040a2030b4d0b0583a5c63ee4087207635e584f116a716be472953bdc442e4be5270cd4614b5eba2021fbd9c011359f3b952e860815985bf1adb5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- key-vortex (0.2.1)
4
+ key-vortex (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,8 +33,11 @@ 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
+ key_vortex-contract (0.2.3)
37
+ rantly (~> 2.0.0)
38
+ rspec (~> 3.0)
37
39
  kwalify (0.7.2)
40
+ language_server-protocol (3.17.0.3)
38
41
  listen (3.8.0)
39
42
  rb-fsevent (~> 0.10, >= 0.10.3)
40
43
  rb-inotify (~> 0.9, >= 0.9.10)
@@ -44,14 +47,17 @@ GEM
44
47
  notiffany (0.1.3)
45
48
  nenv (~> 0.1)
46
49
  shellany (~> 0.0)
47
- parallel (1.22.1)
48
- parser (3.2.2.0)
50
+ parallel (1.23.0)
51
+ parser (3.2.2.3)
49
52
  ast (~> 2.4.1)
53
+ racc
50
54
  pry (0.14.2)
51
55
  coderay (~> 1.1)
52
56
  method_source (~> 1.0)
57
+ racc (1.7.1)
53
58
  rainbow (3.1.1)
54
59
  rake (13.0.6)
60
+ rantly (2.0.0)
55
61
  rb-fsevent (0.11.2)
56
62
  rb-inotify (0.10.1)
57
63
  ffi (~> 1.0)
@@ -59,32 +65,33 @@ GEM
59
65
  kwalify (~> 0.7.0)
60
66
  parser (~> 3.2.0)
61
67
  rainbow (>= 2.0, < 4.0)
62
- regexp_parser (2.7.0)
68
+ regexp_parser (2.8.1)
63
69
  rexml (3.2.5)
64
70
  rspec (3.12.0)
65
71
  rspec-core (~> 3.12.0)
66
72
  rspec-expectations (~> 3.12.0)
67
73
  rspec-mocks (~> 3.12.0)
68
- rspec-core (3.12.1)
74
+ rspec-core (3.12.2)
69
75
  rspec-support (~> 3.12.0)
70
- rspec-expectations (3.12.2)
76
+ rspec-expectations (3.12.3)
71
77
  diff-lcs (>= 1.2.0, < 2.0)
72
78
  rspec-support (~> 3.12.0)
73
- rspec-mocks (3.12.5)
79
+ rspec-mocks (3.12.6)
74
80
  diff-lcs (>= 1.2.0, < 2.0)
75
81
  rspec-support (~> 3.12.0)
76
- rspec-support (3.12.0)
77
- rubocop (1.49.0)
82
+ rspec-support (3.12.1)
83
+ rubocop (1.54.2)
78
84
  json (~> 2.3)
85
+ language_server-protocol (>= 3.17.0)
79
86
  parallel (~> 1.10)
80
- parser (>= 3.2.0.0)
87
+ parser (>= 3.2.2.3)
81
88
  rainbow (>= 2.2.2, < 4.0)
82
89
  regexp_parser (>= 1.8, < 3.0)
83
90
  rexml (>= 3.2.5, < 4.0)
84
91
  rubocop-ast (>= 1.28.0, < 2.0)
85
92
  ruby-progressbar (~> 1.7)
86
93
  unicode-display_width (>= 2.4.0, < 3.0)
87
- rubocop-ast (1.28.0)
94
+ rubocop-ast (1.29.0)
88
95
  parser (>= 3.2.1.0)
89
96
  ruby-progressbar (1.13.0)
90
97
  shellany (0.0.1)
data/README.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # KeyVortex
2
2
 
3
+ KeyVortex provides a common abstraction around storing records in various datastores. It allows for the use of different adapters depending on the environment, and provides constraints to protect programmatically against differing constraints between them.
4
+
5
+ To start using KeyVortex, you'll need to define a record:
6
+
7
+ ```ruby
8
+ require "key_vortex/record"
9
+
10
+ class ExampleRecord < KeyVortex::Record
11
+ field :a, String, length: 20
12
+ field :b, Integer, maximum: 100
13
+ end
14
+ ```
15
+
16
+ Now you can use this object in various ways:
17
+
18
+ ```
19
+ > record = ExampleRecord.new(key: "foo", a: "bar", b: 10)
20
+ => #<ExampleRecord:0x000055fe0b5fe538 @values={:key=>"foo", :a=>"bar", :b=>10}>
21
+ > record.a
22
+ => "bar"
23
+ > record.a = "baz"
24
+ => "baz"
25
+ > record.a
26
+ => "baz"
27
+ > record.b = 1000
28
+ Invalid value 1000 for b (KeyVortex::Error)
29
+ ```
30
+
31
+ You may notice that a `key` field was defined as well. This can be a String up to 36 characters long, to accomodate a GUID if that's what you wish to use.
32
+
33
+
34
+
3
35
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/key_vortex`. To experiment with that code, run `bin/console` for an interactive prompt.
4
36
 
5
37
  TODO: Delete this and the text above, and describe your gem
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "key_vortex"
3
4
  require "key_vortex/adapter"
4
5
 
5
6
  class KeyVortex
6
7
  class Adapter
7
8
  class Memory < KeyVortex::Adapter
9
+ def self.build(items: {}, limitations: [])
10
+ new(items, limitations: limitations)
11
+ end
12
+
8
13
  def initialize(items, limitations: [])
9
14
  super()
10
15
  @items = items
@@ -25,3 +30,5 @@ class KeyVortex
25
30
  end
26
31
  end
27
32
  end
33
+
34
+ KeyVortex.register(KeyVortex::Adapter::Memory)
@@ -13,5 +13,9 @@ class KeyVortex
13
13
  def register_limitation(limitation)
14
14
  @limitations[limitation.type] = limitation
15
15
  end
16
+
17
+ def self.symbol
18
+ name.downcase
19
+ end
16
20
  end
17
21
  end
@@ -25,5 +25,9 @@ class KeyVortex
25
25
  def accepts?(value)
26
26
  limitation.accepts?(value)
27
27
  end
28
+
29
+ def enable_json_additions
30
+ @limitation.enable_json_additions
31
+ end
28
32
  end
29
33
  end
@@ -27,9 +27,9 @@ class KeyVortex
27
27
  end
28
28
 
29
29
  def encompasses_constraint?(constraint)
30
- !applicable_constraints(constraint).select do |con|
30
+ applicable_constraints(constraint).any? do |con|
31
31
  con.within?(constraint)
32
- end.empty?
32
+ end
33
33
  end
34
34
 
35
35
  def within?(limitation)
@@ -39,9 +39,9 @@ class KeyVortex
39
39
  end
40
40
 
41
41
  def within_constraint?(constraint)
42
- !applicable_constraints(constraint).select do |con|
42
+ applicable_constraints(constraint).any? do |con|
43
43
  con.within?(constraint)
44
- end.empty?
44
+ end
45
45
  end
46
46
 
47
47
  def applicable_constraints(constraint)
@@ -54,6 +54,27 @@ class KeyVortex
54
54
  value.is_a?(type) && @constraints.all? { |constraint| constraint.accepts?(value) }
55
55
  end
56
56
 
57
+ JSON_ADDITIONS = {
58
+ BigDecimal: "json/add/bigdecimal",
59
+ Complex: "json/add/complex",
60
+ Date: "json/add/date",
61
+ DateTime: "json/add/date_time",
62
+ Exception: "json/add/exception",
63
+ OpenStruct: "json/add/ostruct",
64
+ Range: "json/add/range",
65
+ Rational: "json/add/rational",
66
+ Regexp: "json/add/regexp",
67
+ Set: "json/add/set",
68
+ Struct: "json/add/struct",
69
+ Symbol: "json/add/symbol",
70
+ Time: "json/add/time"
71
+ }.freeze
72
+
73
+ def enable_json_additions
74
+ path = JSON_ADDITIONS[@type.class.name]
75
+ require path if path
76
+ end
77
+
57
78
  def to_s
58
79
  "Limitation: #{@type}\n\t#{@constraints.join('\n\t')}"
59
80
  end
@@ -25,6 +25,7 @@ class KeyVortex
25
25
 
26
26
  def self.register_field(field)
27
27
  field_hash[field.name] = field
28
+ field.enable_json_additions
28
29
  define_getter(field)
29
30
  define_setter(field)
30
31
  end
@@ -63,5 +64,16 @@ class KeyVortex
63
64
  def ==(other)
64
65
  self.class == other.class && values == other.values
65
66
  end
67
+
68
+ def to_json(*args)
69
+ {
70
+ JSON.create_id => self.class.name,
71
+ "values" => @values
72
+ }.to_json(*args)
73
+ end
74
+
75
+ def self.json_create(object)
76
+ new(object["values"])
77
+ end
66
78
  end
67
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class KeyVortex
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
data/lib/key_vortex.rb CHANGED
@@ -5,6 +5,20 @@ require_relative "key_vortex/version"
5
5
  class KeyVortex
6
6
  class Error < StandardError; end
7
7
 
8
+ def self.register(adapter_class)
9
+ @adapter_registry ||= {}
10
+ @adapter_registry[adapter_class.symbol] = adapter_class
11
+ end
12
+
13
+ def self.vortex(adapter_symbol, record_class, **options)
14
+ new(
15
+ @adapter_registry[adapter_symbol].build(**options),
16
+ record_class
17
+ )
18
+ end
19
+
20
+ attr_reader :adapter, :record_class
21
+
8
22
  def initialize(adapter, record_class)
9
23
  @adapter = adapter
10
24
  @record_class = record_class
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.2.1
4
+ version: 0.2.3
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-11 00:00:00.000000000 Z
11
+ date: 2023-07-13 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.)