teton 0.0.2 → 0.0.3

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: d0ae17f69664066dc41b866710d796b0191718219cd2b8d8ebd46e7ee513e4c4
4
- data.tar.gz: fd29fdac420cd364cf8ef98101f8ac52e2c8a44d569e347c62691e756f226fa3
3
+ metadata.gz: 84509199f54853bad7c82f951f2a83e2bfc1965058f3055f03449234d434ac3d
4
+ data.tar.gz: be10440a0380bf6e2a9df385f4a6bfec59da3d337c2991632d4bd13364e80136
5
5
  SHA512:
6
- metadata.gz: 5562f125e730627254377f95049b5bf636b05423322291fd4a9349075c6b084b0d125c4c9095469e8945a04779c49284fbf0d1937b583331606224acd47968f6
7
- data.tar.gz: 055c6914b343d7288de36d63d3e8ca35b2a2fbe2694d852ce4763438518e90aa6850f8fce1926ad014c95f96a25eafcd823b99c545b8fbf9cc7eb0fce4be02e6
6
+ metadata.gz: 8b85202b1785bce00ff27aaba9e615b6d00db61cdde2eec3a9af2fa661538536d06ab7c9f8e109b3b413577a156f35a3cc54f4772d512ee99c7d2e54a133d925
7
+ data.tar.gz: 231fd68d9615505527dbc2e774b8a5fa7f78418a77296c2670bce272fe5a4c7cc42a4c1051d9b66d02e1b84e5647b6a0e4df103173e7dc3dddcb3efc18271a8c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ #### 0.0.3 - Monday, Sept. 5th, 2022
2
+
3
+ * Paging mechanics added: Db#get now supports `skip` and `limit` optional keyword arguments.
1
4
 
2
5
  #### 0.0.2 - Monday, Sept. 5th, 2022
3
6
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/teton.svg)](https://badge.fury.io/rb/teton) [![Ruby Gem CI](https://github.com/mattruggio/teton/actions/workflows/rubygem.yml/badge.svg)](https://github.com/mattruggio/teton/actions/workflows/rubygem.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/787a5d512223e85efd69/maintainability)](https://codeclimate.com/github/mattruggio/teton/maintainability) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
4
 
5
- #### Hierarchical key-value object store interface
5
+ #### Hierarchical key-value object store
6
6
 
7
7
  ---
8
8
 
@@ -26,12 +26,16 @@ bundle add teton
26
26
 
27
27
  The main API is made up of these instance methods:
28
28
 
29
- Method | Description
30
- ------------------- | -----------
31
- `Db#set(key, data)` | Set an entries data to the passed in values.
32
- `Db#get(key)` | Get the entry if it exists or nil if it does not. If the key is a resource then it will always return an array.
33
- `Db#del(key)` | Delete the key and all children of the key from the store.
34
- `Db#count(key)` | The number of entries directly under a key if the key is a resource. If they key is an entry then 1 if the entry exists and 0 if it does not exist.
29
+ Method | Description
30
+ ---------------------------------------| --------------------------------------------------------------
31
+ `Db#set(key, data = {})` | Set an entries data to the passed in values.
32
+ `Db#get(key, limit: nil, skip: nil)` | Get the entry if it exists or nil if it does not. If the key is a resource then it will always return an array.
33
+ `Db#del(key)` | Delete the key and all children of the key from the store.
34
+ `Db#count(key)` | The number of entries directly under a key if the key is a resource. If they key is an entry then 1 if the entry exists and 0 if it does not exist.
35
+
36
+ Note(s):
37
+
38
+ * limit and skip are optional and only apply to resource keys, not entry keys.
35
39
 
36
40
  #### Setting Up Database
37
41
 
data/lib/teton/db.rb CHANGED
@@ -30,8 +30,12 @@ module Teton
30
30
  self
31
31
  end
32
32
 
33
- def get(key)
34
- store.get(key(key))
33
+ def get(key, limit: nil, skip: nil)
34
+ store.get(
35
+ key(key),
36
+ limit: zero_floor_or_nil(limit),
37
+ skip: zero_floor_or_nil(skip)
38
+ )
35
39
  end
36
40
 
37
41
  def del(key)
@@ -44,6 +48,12 @@ module Teton
44
48
 
45
49
  private
46
50
 
51
+ def zero_floor_or_nil(value)
52
+ return unless value
53
+
54
+ value ? [value, 0].max : nil
55
+ end
56
+
47
57
  def key(key)
48
58
  key.is_a?(Key) ? key : Key.new(key, separator: separator)
49
59
  end
data/lib/teton/entry.rb CHANGED
@@ -15,7 +15,7 @@ module Teton
15
15
  end
16
16
 
17
17
  def [](data_key)
18
- data[data_key]
18
+ data[data_key.to_s]
19
19
  end
20
20
 
21
21
  def to_s
@@ -27,13 +27,13 @@ module Teton
27
27
  self
28
28
  end
29
29
 
30
- def get(key)
30
+ def get(key, limit: nil, skip: nil)
31
31
  store_pointer = traverse_to_last(key)
32
32
 
33
33
  return unless store_pointer
34
34
 
35
35
  if key.resource?
36
- entries(key, store_pointer, key.last_part)
36
+ entries(key, store_pointer, key.last_part, limit: limit, skip: skip)
37
37
  else
38
38
  entry(key, store_pointer, key.last_part)
39
39
  end
@@ -158,14 +158,20 @@ module Teton
158
158
  )
159
159
  end
160
160
 
161
- def entries(key, pointer, part)
161
+ def entries(key, pointer, part, limit: nil, skip: nil)
162
162
  pointer = pointer.dig(part, IDS_KEY)
163
163
 
164
164
  return [] unless pointer
165
165
 
166
- pointer.map do |inner_part, value|
166
+ start_index = skip || 0
167
+ end_index = limit ? (start_index + limit - 1) : -1
168
+ selected_keys = pointer.keys[start_index..end_index] || []
169
+
170
+ selected_keys.map do |selected_key|
171
+ value = pointer[selected_key]
172
+
167
173
  Entry.new(
168
- key.to_s(inner_part),
174
+ key.to_s(selected_key),
169
175
  data: value[DATA_KEY],
170
176
  created_at: value[META_KEY][CREATED_AT_KEY],
171
177
  updated_at: value[META_KEY][UPDATED_AT_KEY]
data/lib/teton/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Teton
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
data/teton.gemspec CHANGED
@@ -5,7 +5,7 @@ require './lib/teton/version'
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'teton'
7
7
  s.version = Teton::VERSION
8
- s.summary = 'Hierarchical key-value object store interface.'
8
+ s.summary = 'Hierarchical key-value object store.'
9
9
 
10
10
  s.description = 'Store key-value pair objects in a discoverable hierarchy. Provides a pluggable interface for multiple back-ends.'
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-05 00:00:00.000000000 Z
11
+ date: 2022-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-audit
@@ -214,5 +214,5 @@ requirements: []
214
214
  rubygems_version: 3.1.6
215
215
  signing_key:
216
216
  specification_version: 4
217
- summary: Hierarchical key-value object store interface.
217
+ summary: Hierarchical key-value object store.
218
218
  test_files: []