tablesalt 0.9.0 → 0.9.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: 98464db22a1b0b302a57d7000038552ca3e8752c2266afd130531ed933b188e9
4
- data.tar.gz: bc6ca9ddaa87e1ab9d690d11693a14a82bacd6b5992323967887a6f430d1b766
3
+ metadata.gz: 38c31dee2d7e9d19fbcecf535911312665e5f35d741da7119de8655eecaa40d9
4
+ data.tar.gz: 873c8d1b89c32ca218a62b812173d0f556c0ccff592163cf0b324baf25154909
5
5
  SHA512:
6
- metadata.gz: 848bb9e33da015bd099640490ae46894f50c0c96b5c91c9dfc3bfa5402ca6b46d45e88c3ff58a8a202b72bcfffa79cc70a0b078b095ee2e5dda99d48224435de
7
- data.tar.gz: b8b37008b442ce4be113d64fbdf573300e7eb8ec3e19dd0cf2db27d95c608a0782cadca93e0ca9c50df6165ab582ca22da8ebbebe279b3e7523b6a51aa103f08
6
+ metadata.gz: dd1a3f97c91b6a9e68966aa75544a67b6a9fcb42b48f9921e03e32effa0102cf010e2283debf677d626c7fea1b48af1532242a7603bc8dd9b2cf53442d46cd6e
7
+ data.tar.gz: b718d3ab6ea82dcd59ec670a591ab62f475016ac37b22d4763b1bb7a1618f3d5fb8ab15b9ea5d30a9a9d71562266eb0bb522f314689436d72237310a3b1fc3ac
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Tablesalt
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.9.0"
5
+ VERSION = "0.9.1"
6
6
  end
data/lib/tablesalt.rb CHANGED
@@ -8,6 +8,4 @@ require "technologic"
8
8
 
9
9
  require "tablesalt/version"
10
10
 
11
- require "tablesalt/redis_hash_base"
12
-
13
11
  module Tablesalt; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tablesalt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Minneti
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.0
33
+ version: 0.9.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.0
40
+ version: 0.9.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redis
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -63,20 +63,6 @@ files:
63
63
  - LICENSE.txt
64
64
  - README.md
65
65
  - lib/tablesalt.rb
66
- - lib/tablesalt/redis_hash/accessors.rb
67
- - lib/tablesalt/redis_hash/adapter.rb
68
- - lib/tablesalt/redis_hash/callbacks.rb
69
- - lib/tablesalt/redis_hash/comparisons.rb
70
- - lib/tablesalt/redis_hash/converters.rb
71
- - lib/tablesalt/redis_hash/core.rb
72
- - lib/tablesalt/redis_hash/default.rb
73
- - lib/tablesalt/redis_hash/deletions.rb
74
- - lib/tablesalt/redis_hash/enumerators.rb
75
- - lib/tablesalt/redis_hash/identity.rb
76
- - lib/tablesalt/redis_hash/insertions.rb
77
- - lib/tablesalt/redis_hash/mutations.rb
78
- - lib/tablesalt/redis_hash/predicates.rb
79
- - lib/tablesalt/redis_hash_base.rb
80
66
  - lib/tablesalt/version.rb
81
67
  homepage: https://github.com/Freshly/spicerack/tree/master/tablesalt
82
68
  licenses:
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Accessors allow for the retrieval of data from the Hash.
4
- module Tablesalt
5
- module RedisHash
6
- module Accessors
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- delegate :assoc, :compact, :dig, :fetch_values, :flatten, :key, :rassoc, :rehash, to: :to_h
11
- end
12
-
13
- def [](field)
14
- hget(redis_key, field) || default(field)
15
- end
16
-
17
- def fetch(field, default = nil)
18
- value = self[field]
19
- return value if value.present?
20
- return yield(field) if block_given?
21
- return default unless default.nil?
22
-
23
- raise KeyError, "key not found: \"#{field}\""
24
- end
25
-
26
- def keys
27
- hkeys(redis_key)
28
- end
29
-
30
- def length
31
- hlen(redis_key)
32
- end
33
- alias_method :size, :length
34
-
35
- def values
36
- hvals(redis_key)
37
- end
38
-
39
- def values_at(*fields)
40
- hmget(*fields.flatten.unshift(redis_key))
41
- end
42
- end
43
- end
44
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Adapter which handles the storage and retrieval of hash data in Redis.
4
- module Tablesalt
5
- module RedisHash
6
- module Adapter
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- attr_reader :redis_key, :redis
11
-
12
- delegate :del, :hdel, :hexists, :hget, :hgetall, :hkeys, :hlen, :hmget, :hmset, :hset, :hvals, to: :redis
13
- delegate :default_redis, :default_redis_key, to: :class
14
-
15
- private
16
-
17
- def initialize_redis(redis, redis_key)
18
- @redis = redis || default_redis
19
- @redis_key = redis_key || default_redis_key
20
- end
21
- end
22
-
23
- class_methods do
24
- def default_redis
25
- Redis.new
26
- end
27
-
28
- def default_redis_key
29
- SecureRandom.hex
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Callbacks provide an extensible mechanism for hooking into a RedisHash.
4
- module Tablesalt
5
- module RedisHash
6
- module Callbacks
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- include ActiveSupport::Callbacks
11
- define_callbacks :initialize, :reload
12
- end
13
- end
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Comparisons encompasses equality and set inclusion.
4
- module Tablesalt
5
- module RedisHash
6
- module Comparisons
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- delegate :<, :<=, :>, :>=, :compare_by_identity, :compare_by_identity?, to: :to_h
11
- end
12
-
13
- def eql?(other)
14
- other.hash == hash
15
- end
16
- alias_method :==, :eql?
17
- end
18
- end
19
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Converters allow for other objects to be coerced into a RedisHash.
4
- module Tablesalt
5
- module RedisHash
6
- module Converters
7
- extend ActiveSupport::Concern
8
-
9
- class_methods do
10
- def [](*arguments)
11
- options = block_given? ? yield({}) : {}
12
- new(**options).merge!(Hash[*arguments])
13
- end
14
-
15
- def try_convert(object, &block)
16
- return object if object.is_a?(RedisHash)
17
-
18
- self[object, &block] if object.respond_to?(:to_hash)
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # A RedisHash is a wrapper around a h<key> stored in Redis.
4
- module Tablesalt
5
- module RedisHash
6
- module Core
7
- extend ActiveSupport::Concern
8
-
9
- def initialize(default = nil, redis_key: nil, redis: nil, &block)
10
- run_callbacks(:initialize) do
11
- initialize_default(default, &block)
12
- initialize_redis(redis, redis_key)
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # A Default allows a static or procedurally generated value to be returned on failed lookups.
4
- module Tablesalt
5
- module RedisHash
6
- module Default
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- attr_reader :default_proc
11
-
12
- private
13
-
14
- def initialize_default(default, &block)
15
- raise ArgumentError, "cannot specify both block and static default" if block_given? && default.present?
16
-
17
- set_default(default, &block)
18
- end
19
-
20
- def set_default(default, &block)
21
- self.default = default if default.present?
22
- self.default_proc = block if block_given?
23
- end
24
-
25
- def to_default(field = nil, allow_nil_field: true)
26
- @default.presence || (default_proc&.call(self, field) if !field.nil? || allow_nil_field)
27
- end
28
-
29
- def validate_proc(proc)
30
- raise TypeError, "wrong default_proc type #{proc.class.name} (expected Proc)" unless proc.is_a? Proc
31
-
32
- validate_lambda_arity(proc.arity) if proc.lambda?
33
- end
34
-
35
- def validate_lambda_arity(arity)
36
- raise TypeError, "default_proc takes two arguments (2 for #{arity})" if arity >= 0 && arity != 2
37
- end
38
- end
39
-
40
- def default=(value)
41
- @default = value
42
- @default_proc = nil
43
- end
44
-
45
- def default_proc=(value)
46
- validate_proc(value) unless value.nil?
47
-
48
- @default = nil
49
- @default_proc = value
50
- end
51
-
52
- def default(field = nil)
53
- to_default(field, allow_nil_field: false)
54
- end
55
- end
56
- end
57
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Deletions allow for the removal of data from the Hash.
4
- module Tablesalt
5
- module RedisHash
6
- module Deletions
7
- extend ActiveSupport::Concern
8
-
9
- def clear
10
- del(redis_key) and {}
11
- end
12
-
13
- def delete(field)
14
- value = self[field]
15
- result = hdel(redis_key, field)
16
- (result == 0 && block_given?) ? yield(field) : value
17
- end
18
-
19
- def shift
20
- return to_default if empty?
21
-
22
- field = keys.first
23
- [ field, delete(field) ]
24
- end
25
- end
26
- end
27
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Enumerators allow for the traversal and manipulation of data in the Hash.
4
- module Tablesalt
5
- module RedisHash
6
- module Enumerators
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- delegate :each, :each_pair, :each_key, :each_value, :reject, :select, :transform_values, to: :to_h
11
- end
12
-
13
- def delete_if
14
- return enum_for(__method__) unless block_given?
15
-
16
- each { |field, value| delete(field) if yield(field, value) }
17
-
18
- to_h
19
- end
20
-
21
- def keep_if
22
- return enum_for(__method__) unless block_given?
23
-
24
- delete_if { |field, value| !yield(field, value) }
25
- end
26
-
27
- def reject!(&block)
28
- return enum_for(__method__) unless block_given?
29
-
30
- original = to_h
31
- delete_if(&block)
32
- current = to_h
33
-
34
- (original == current) ? nil : current
35
- end
36
-
37
- def select!
38
- return enum_for(__method__) unless block_given?
39
-
40
- reject! { |*arguments| !yield(*arguments) }
41
- end
42
-
43
- def transform_values!
44
- return enum_for(__method__) unless block_given?
45
-
46
- each { |field, value| store(field, yield(value)) }
47
-
48
- to_h
49
- end
50
- end
51
- end
52
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Identity relates to the specific object instance.
4
- module Tablesalt
5
- module RedisHash
6
- module Identity
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- delegate :inspect, :to_proc, :to_s, to: :to_h
11
- end
12
-
13
- def hash
14
- { redis_id: redis.id, redis_key: redis_key }.hash
15
- end
16
-
17
- def to_hash
18
- to_h
19
- end
20
-
21
- def to_h
22
- hgetall(redis_key)
23
- end
24
- end
25
- end
26
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Insertions allow for the addition of data into the RedisHash.
4
- module Tablesalt
5
- module RedisHash
6
- module Insertions
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- delegate :merge, to: :to_h
11
- end
12
-
13
- def merge!(other_hash)
14
- hmset(*other_hash.to_a.unshift(redis_key))
15
- self
16
- end
17
- alias_method :update, :merge!
18
-
19
- def store(field, value)
20
- hset(redis_key, field, value)
21
- end
22
- alias_method :[]=, :store
23
- end
24
- end
25
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Mutations allow for the manipulation of data in the Hash.
4
- module Tablesalt
5
- module RedisHash
6
- module Mutations
7
- extend ActiveSupport::Concern
8
-
9
- def compact!
10
- delete_if { |_, value| value.blank? }
11
- end
12
-
13
- def invert
14
- inversion = to_h.invert
15
- clear
16
- inversion.each { |key, value| self[key] = value }
17
- end
18
-
19
- def replace(other_hash)
20
- clear and merge!(other_hash)
21
- end
22
- end
23
- end
24
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Predicates enable querying the Hash for data.
4
- module Tablesalt
5
- module RedisHash
6
- module Predicates
7
- extend ActiveSupport::Concern
8
-
9
- def any?(&block)
10
- return length > 0 unless block_given?
11
-
12
- to_h.any?(&block)
13
- end
14
-
15
- def empty?
16
- length == 0
17
- end
18
-
19
- def include?(field)
20
- hexists(redis_key, field)
21
- end
22
- alias_method :has_key?, :include?
23
- alias_method :key?, :include?
24
- alias_method :member?, :include?
25
-
26
- def value?(value)
27
- values.include? value
28
- end
29
- alias_method :has_value?, :value?
30
- end
31
- end
32
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "redis_hash/adapter"
4
- require_relative "redis_hash/default"
5
- require_relative "redis_hash/callbacks"
6
- require_relative "redis_hash/core"
7
- require_relative "redis_hash/identity"
8
- require_relative "redis_hash/accessors"
9
- require_relative "redis_hash/comparisons"
10
- require_relative "redis_hash/predicates"
11
- require_relative "redis_hash/insertions"
12
- require_relative "redis_hash/deletions"
13
- require_relative "redis_hash/enumerators"
14
- require_relative "redis_hash/mutations"
15
- require_relative "redis_hash/converters"
16
-
17
- module Tablesalt
18
- class RedisHashBase
19
- include Technologic
20
- include Tablesalt::RedisHash::Adapter
21
- include Tablesalt::RedisHash::Default
22
- include Tablesalt::RedisHash::Callbacks
23
- include Tablesalt::RedisHash::Core
24
- include Tablesalt::RedisHash::Identity
25
- include Tablesalt::RedisHash::Accessors
26
- include Tablesalt::RedisHash::Comparisons
27
- include Tablesalt::RedisHash::Predicates
28
- include Tablesalt::RedisHash::Insertions
29
- include Tablesalt::RedisHash::Deletions
30
- include Tablesalt::RedisHash::Enumerators
31
- include Tablesalt::RedisHash::Mutations
32
- include Tablesalt::RedisHash::Converters
33
- end
34
- end