key-vortex 0.2.2 → 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: 2fcc61bdf13488c6d20e7f6aa4e889852a37ef52b4ea341d8f4c62c40afe8426
4
- data.tar.gz: e219c616d9a53e0874221e3ff748a2b4c608dd7c03c86fa765f3f13ffbfabc09
3
+ metadata.gz: 5f5d707741ec015d0e2b2550267246b8d59ba9adf324cdbfd2502a81aedecfa1
4
+ data.tar.gz: f852c54e10c99863649639ab7974e81a93dc91403969d9cfaabd35ff068bdc67
5
5
  SHA512:
6
- metadata.gz: df02551af7fd966c79f390ea2e15c5984540774eaf23c8770593ac3f750277eebec72975d10d6c8fa80216cd3096689caaf565308b3629d6eb1e7383ee0c6279
7
- data.tar.gz: 294e8d44baddfb66d5c909754cf1f48aac50af12fedde35dc9d81e73e8ea68efb1a7a623283229eae745ff19cea284f19b5c08925147089b9b99ff87afe97235
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.2)
4
+ key-vortex (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,7 +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.1.2)
36
+ key_vortex-contract (0.2.3)
37
37
  rantly (~> 2.0.0)
38
38
  rspec (~> 3.0)
39
39
  kwalify (0.7.2)
@@ -80,7 +80,7 @@ GEM
80
80
  diff-lcs (>= 1.2.0, < 2.0)
81
81
  rspec-support (~> 3.12.0)
82
82
  rspec-support (3.12.1)
83
- rubocop (1.54.1)
83
+ rubocop (1.54.2)
84
84
  json (~> 2.3)
85
85
  language_server-protocol (>= 3.17.0)
86
86
  parallel (~> 1.10)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class KeyVortex
4
- VERSION = "0.2.2"
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key-vortex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lambda Null