tablesalt 0.8.4 → 0.9.0

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: d4f0e11454d95394d0070ffa386056836628db24f0070be4524ea5cf70a17912
4
- data.tar.gz: 1b27619517487c59c84324b3c8313755ad2274a15eecba5b8ff1e17355cae3e7
3
+ metadata.gz: 98464db22a1b0b302a57d7000038552ca3e8752c2266afd130531ed933b188e9
4
+ data.tar.gz: bc6ca9ddaa87e1ab9d690d11693a14a82bacd6b5992323967887a6f430d1b766
5
5
  SHA512:
6
- metadata.gz: 92d11b14fe9b71135e9b75e23bc885070854fac486982be65802aec6b2462b9a724fc75d5e5345985b0cd7e973cd213ecfa285c5089827632759501b3b3773c2
7
- data.tar.gz: 11a193ee36b492d3c3167cb9ad6668de036b99dd8341924c05b47ec7e63d847b53855d83e416c8ee9cb146cd8350b015ef9a612afef780621ef9e240d05a442e
6
+ metadata.gz: 848bb9e33da015bd099640490ae46894f50c0c96b5c91c9dfc3bfa5402ca6b46d45e88c3ff58a8a202b72bcfffa79cc70a0b078b095ee2e5dda99d48224435de
7
+ data.tar.gz: b8b37008b442ce4be113d64fbdf573300e7eb8ec3e19dd0cf2db27d95c608a0782cadca93e0ca9c50df6165ab582ca22da8ebbebe279b3e7523b6a51aa103f08
@@ -0,0 +1,34 @@
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
@@ -6,25 +6,10 @@ module Tablesalt
6
6
  module Core
7
7
  extend ActiveSupport::Concern
8
8
 
9
- included do
10
- attr_reader :redis_key, :redis
11
- delegate :del, :hdel, :hexists, :hget, :hgetall, :hkeys, :hlen, :hmget, :hmset, :hset, :hvals, to: :redis
12
-
13
- private
14
-
15
- def set_default(default, &block)
16
- self.default = default if default.present?
17
- self.default_proc = block if block_given?
18
- end
19
- end
20
-
21
- def initialize(default = nil, redis_key: SecureRandom.hex, redis: Redis.new, &block)
22
- raise ArgumentError, "cannot specify both block and static default" if block_given? && default.present?
23
-
9
+ def initialize(default = nil, redis_key: nil, redis: nil, &block)
24
10
  run_callbacks(:initialize) do
25
- set_default(default, &block)
26
- @redis_key = redis_key
27
- @redis = redis
11
+ initialize_default(default, &block)
12
+ initialize_redis(redis, redis_key)
28
13
  end
29
14
  end
30
15
  end
@@ -11,6 +11,17 @@ module Tablesalt
11
11
 
12
12
  private
13
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
+
14
25
  def to_default(field = nil, allow_nil_field: true)
15
26
  @default.presence || (default_proc&.call(self, field) if !field.nil? || allow_nil_field)
16
27
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "redis_hash/adapter"
3
4
  require_relative "redis_hash/default"
4
5
  require_relative "redis_hash/callbacks"
5
6
  require_relative "redis_hash/core"
@@ -16,6 +17,7 @@ require_relative "redis_hash/converters"
16
17
  module Tablesalt
17
18
  class RedisHashBase
18
19
  include Technologic
20
+ include Tablesalt::RedisHash::Adapter
19
21
  include Tablesalt::RedisHash::Default
20
22
  include Tablesalt::RedisHash::Callbacks
21
23
  include Tablesalt::RedisHash::Core
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Tablesalt
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.8.4"
5
+ VERSION = "0.9.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tablesalt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Minneti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-15 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.4
33
+ version: 0.9.0
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.8.4
40
+ version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redis
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +64,7 @@ files:
64
64
  - README.md
65
65
  - lib/tablesalt.rb
66
66
  - lib/tablesalt/redis_hash/accessors.rb
67
+ - lib/tablesalt/redis_hash/adapter.rb
67
68
  - lib/tablesalt/redis_hash/callbacks.rb
68
69
  - lib/tablesalt/redis_hash/comparisons.rb
69
70
  - lib/tablesalt/redis_hash/converters.rb
@@ -77,7 +78,7 @@ files:
77
78
  - lib/tablesalt/redis_hash/predicates.rb
78
79
  - lib/tablesalt/redis_hash_base.rb
79
80
  - lib/tablesalt/version.rb
80
- homepage: https://www.freshly.com
81
+ homepage: https://github.com/Freshly/spicerack/tree/master/tablesalt
81
82
  licenses:
82
83
  - MIT
83
84
  metadata: {}