strum-cache 0.0.4 → 0.1.0
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 +4 -4
- data/.gitlab-ci.yml +3 -0
- data/.rubocop.yml +1 -6
- data/Gemfile.lock +31 -40
- data/lib/strum/cache.rb +6 -2
- data/lib/strum/cache/version.rb +1 -1
- data/lib/strum/cache_utils/build_resource_url.rb +12 -5
- data/lib/strum/cache_utils/build_resources_url.rb +1 -0
- data/lib/strum/cache_utils/find.rb +1 -1
- data/lib/strum/cache_utils/redis.rb +1 -0
- data/lib/strum/cache_utils/redis_storage.rb +8 -1
- data/lib/strum/cache_utils/search.rb +1 -1
- data/lib/strum/cache_utils/send_request.rb +21 -9
- data/strum-cache.gemspec +7 -5
- metadata +42 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 429d0ccabdab8e28ec3066321eafcf0bbc26ecfbb4d22c21dfc01af7e0eba64b
|
4
|
+
data.tar.gz: c53417e84ea5c1a96ff22c13e9d33d8ddb3cc499eac3f7e655d5cf6523696c57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89dfcc215197a83d4ec352691d3d1daeb1eaf3a7f9035c17791228bd3dad3e96a508d58c7f6ffc884727339aaedf733978c2373fd359a73860b00049b8003e92
|
7
|
+
data.tar.gz: 69e51b5ae67c37ce8052665af3f1e63cfb756b2a29e714b92809c15b8962c5224bb8f25a0cdab87d6d6f54198660717abceecd760d39c5e7f246aaa1b4b5d74d
|
data/.gitlab-ci.yml
ADDED
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.7
|
3
3
|
NewCops: enable
|
4
4
|
|
5
5
|
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
@@ -12,15 +12,10 @@ Layout/IndentationConsistency:
|
|
12
12
|
Enabled: true
|
13
13
|
EnforcedStyle: indented_internal_methods
|
14
14
|
|
15
|
-
# Two spaces, no tabs (for indentation).
|
16
|
-
Layout/IndentationWidth:
|
17
|
-
Enabled: true
|
18
|
-
|
19
15
|
# Check quotes usage according to lint rule below.
|
20
16
|
Style/StringLiterals:
|
21
17
|
Enabled: true
|
22
18
|
EnforcedStyle: double_quotes
|
23
19
|
|
24
20
|
Layout/LineLength:
|
25
|
-
Max: 120
|
26
21
|
IgnoredPatterns: ['\A#']
|
data/Gemfile.lock
CHANGED
@@ -1,70 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
strum-cache (0.0
|
4
|
+
strum-cache (0.1.0)
|
5
5
|
dry-configurable (~> 0.11.6)
|
6
6
|
dry-inflector (~> 0.2)
|
7
7
|
faraday (~> 1.1)
|
8
8
|
json (~> 2.3)
|
9
9
|
redis (~> 4.2)
|
10
|
-
strum
|
10
|
+
strum-json (~> 0.0.2)
|
11
|
+
strum-pipe (~> 0.0.3)
|
12
|
+
strum-service (~> 0.1)
|
11
13
|
|
12
14
|
GEM
|
13
15
|
remote: https://rubygems.org/
|
14
16
|
specs:
|
15
17
|
addressable (2.7.0)
|
16
18
|
public_suffix (>= 2.0.2, < 5.0)
|
17
|
-
ast (2.4.
|
18
|
-
concurrent-ruby (1.1.
|
19
|
+
ast (2.4.2)
|
20
|
+
concurrent-ruby (1.1.9)
|
19
21
|
debase (0.2.4.1)
|
20
22
|
debase-ruby_core_source (>= 0.10.2)
|
21
|
-
debase-ruby_core_source (0.10.
|
23
|
+
debase-ruby_core_source (0.10.12)
|
22
24
|
diff-lcs (1.4.4)
|
23
25
|
dry-configurable (0.11.6)
|
24
26
|
concurrent-ruby (~> 1.0)
|
25
27
|
dry-core (~> 0.4, >= 0.4.7)
|
26
28
|
dry-equalizer (~> 0.2)
|
27
|
-
dry-
|
28
|
-
concurrent-ruby (~> 1.0)
|
29
|
-
dry-configurable (~> 0.1, >= 0.1.3)
|
30
|
-
dry-core (0.5.0)
|
29
|
+
dry-core (0.6.0)
|
31
30
|
concurrent-ruby (~> 1.0)
|
32
31
|
dry-equalizer (0.3.0)
|
33
32
|
dry-inflector (0.2.0)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
dry-core (~> 0.4, >= 0.4.4)
|
39
|
-
dry-equalizer (~> 0.3)
|
40
|
-
dry-types (~> 1.3)
|
41
|
-
ice_nine (~> 0.11)
|
42
|
-
dry-types (1.4.0)
|
43
|
-
concurrent-ruby (~> 1.0)
|
44
|
-
dry-container (~> 0.3)
|
45
|
-
dry-core (~> 0.4, >= 0.4.4)
|
46
|
-
dry-equalizer (~> 0.3)
|
47
|
-
dry-inflector (~> 0.1, >= 0.1.2)
|
48
|
-
dry-logic (~> 1.0, >= 1.0.2)
|
49
|
-
faraday (1.3.0)
|
33
|
+
faraday (1.4.2)
|
34
|
+
faraday-em_http (~> 1.0)
|
35
|
+
faraday-em_synchrony (~> 1.0)
|
36
|
+
faraday-excon (~> 1.1)
|
50
37
|
faraday-net_http (~> 1.0)
|
38
|
+
faraday-net_http_persistent (~> 1.1)
|
51
39
|
multipart-post (>= 1.2, < 3)
|
52
|
-
ruby2_keywords
|
53
|
-
faraday-
|
54
|
-
|
40
|
+
ruby2_keywords (>= 0.0.4)
|
41
|
+
faraday-em_http (1.0.0)
|
42
|
+
faraday-em_synchrony (1.0.0)
|
43
|
+
faraday-excon (1.1.0)
|
44
|
+
faraday-net_http (1.0.1)
|
45
|
+
faraday-net_http_persistent (1.1.0)
|
55
46
|
json (2.5.1)
|
56
47
|
json-schema (2.8.1)
|
57
48
|
addressable (>= 2.4)
|
58
49
|
multipart-post (2.1.1)
|
59
50
|
parallel (1.20.1)
|
60
|
-
parser (3.0.
|
51
|
+
parser (3.0.1.1)
|
61
52
|
ast (~> 2.4.1)
|
62
53
|
public_suffix (4.0.6)
|
63
54
|
rainbow (3.0.0)
|
64
55
|
rake (13.0.3)
|
65
56
|
redis (4.2.5)
|
66
|
-
regexp_parser (2.
|
67
|
-
rexml (3.2.
|
57
|
+
regexp_parser (2.1.1)
|
58
|
+
rexml (3.2.5)
|
68
59
|
rspec (3.10.0)
|
69
60
|
rspec-core (~> 3.10.0)
|
70
61
|
rspec-expectations (~> 3.10.0)
|
@@ -74,10 +65,10 @@ GEM
|
|
74
65
|
rspec-expectations (3.10.1)
|
75
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
76
67
|
rspec-support (~> 3.10.0)
|
77
|
-
rspec-mocks (3.10.
|
68
|
+
rspec-mocks (3.10.2)
|
78
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
79
70
|
rspec-support (~> 3.10.0)
|
80
|
-
rspec-support (3.10.
|
71
|
+
rspec-support (3.10.2)
|
81
72
|
rubocop (0.90.0)
|
82
73
|
parallel (~> 1.10)
|
83
74
|
parser (>= 2.7.1.1)
|
@@ -92,15 +83,15 @@ GEM
|
|
92
83
|
ruby-debug-ide (0.7.2)
|
93
84
|
rake (>= 0.8.1)
|
94
85
|
ruby-progressbar (1.11.0)
|
95
|
-
ruby2_keywords (0.0.
|
96
|
-
|
97
|
-
strum (0.1.3)
|
86
|
+
ruby2_keywords (0.0.4)
|
87
|
+
strum-json (0.0.2)
|
98
88
|
dry-inflector (~> 0.2.0)
|
99
|
-
|
89
|
+
json (~> 2.3)
|
100
90
|
json-schema (~> 2.8.1)
|
101
|
-
|
102
|
-
|
103
|
-
|
91
|
+
strum-service (~> 0.1.0)
|
92
|
+
strum-pipe (0.0.3)
|
93
|
+
strum-service (~> 0.1)
|
94
|
+
strum-service (0.1.2)
|
104
95
|
unicode-display_width (1.7.0)
|
105
96
|
|
106
97
|
PLATFORMS
|
data/lib/strum/cache.rb
CHANGED
@@ -10,6 +10,7 @@ require "strum/cache_utils/find"
|
|
10
10
|
require "strum/cache_utils/search"
|
11
11
|
|
12
12
|
module Strum
|
13
|
+
# rubocop: disable Style/Documentation
|
13
14
|
module Cache
|
14
15
|
extend Dry::Configurable
|
15
16
|
|
@@ -18,6 +19,7 @@ module Strum
|
|
18
19
|
|
19
20
|
class Error < StandardError; end
|
20
21
|
|
22
|
+
# rubocop: disable Metrics/AbcSize,Metrics/MethodLength
|
21
23
|
def self.const_missing(resource_name)
|
22
24
|
# Strum::Cache::Entity::Find.(id)
|
23
25
|
# Strum::Cache::Entity::Search.(params)
|
@@ -55,7 +57,7 @@ module Strum
|
|
55
57
|
include Strum::Service
|
56
58
|
|
57
59
|
define_method :call do
|
58
|
-
if entity = from_cache_by_id(input) || find_by_id(input)
|
60
|
+
if (entity = from_cache_by_id(input) || find_by_id(input))
|
59
61
|
output(entity)
|
60
62
|
else
|
61
63
|
not_found
|
@@ -90,7 +92,7 @@ module Strum
|
|
90
92
|
include Strum::Service
|
91
93
|
|
92
94
|
define_method :call do
|
93
|
-
if entity = from_cache_by_params || search_by_params
|
95
|
+
if (entity = from_cache_by_params || search_by_params)
|
94
96
|
output(entity)
|
95
97
|
else
|
96
98
|
not_found
|
@@ -121,5 +123,7 @@ module Strum
|
|
121
123
|
end)
|
122
124
|
end
|
123
125
|
end
|
126
|
+
# rubocop: enable Metrics/AbcSize,Metrics/MethodLength
|
124
127
|
end
|
128
|
+
# rubocop: enable Style/Documentation
|
125
129
|
end
|
data/lib/strum/cache/version.rb
CHANGED
@@ -4,15 +4,11 @@ require "strum/cache_utils/build_resources_url"
|
|
4
4
|
|
5
5
|
module Strum
|
6
6
|
module CacheUtils
|
7
|
+
# Resource url builder
|
7
8
|
class BuildResourceUrl
|
8
9
|
include Strum::Service
|
9
10
|
|
10
11
|
def call
|
11
|
-
underscore_resource_code = inflector.underscore(resource_code)
|
12
|
-
base_url = ENV.fetch("#{underscore_resource_code.upcase}_RESOURCE_URL") do
|
13
|
-
host = ENV.fetch("BASE_RESOURCE_URL")
|
14
|
-
File.join(host, inflector.pluralize(underscore_resource_code.gsub(/_/, "-")))
|
15
|
-
end
|
16
12
|
output(url: File.join(base_url, resource_id.to_s))
|
17
13
|
rescue KeyError
|
18
14
|
Strum::CacheUtils::BuildResourcesUrl.call(resource_code: resource_code, params: { id: resource_id }) do |m|
|
@@ -30,6 +26,17 @@ module Strum
|
|
30
26
|
def inflector
|
31
27
|
@inflector ||= Dry::Inflector.new
|
32
28
|
end
|
29
|
+
|
30
|
+
def underscore_resource_code
|
31
|
+
inflector.underscore(resource_code)
|
32
|
+
end
|
33
|
+
|
34
|
+
def base_url
|
35
|
+
ENV.fetch("#{underscore_resource_code.upcase}_RESOURCE_URL") do
|
36
|
+
host = ENV.fetch("BASE_RESOURCE_URL")
|
37
|
+
File.join(host, inflector.pluralize(underscore_resource_code.gsub(/_/, "-")))
|
38
|
+
end
|
39
|
+
end
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
@@ -5,7 +5,9 @@ require "redis"
|
|
5
5
|
|
6
6
|
module Strum
|
7
7
|
module CacheUtils
|
8
|
+
# Redis storage
|
8
9
|
module RedisStorage
|
10
|
+
# rubocop: disable Metrics/MethodLength, Metrics/AbcSize
|
9
11
|
def self.const_missing(resource_name)
|
10
12
|
const_set(resource_name.to_s.strip.capitalize, Class.new do
|
11
13
|
include Singleton
|
@@ -13,10 +15,15 @@ module Strum
|
|
13
15
|
|
14
16
|
define_method :initialize do
|
15
17
|
redis_url = ENV.fetch("#{resource_name.upcase}_CACHE_REDIS_URL", ENV.fetch("CACHE_REDIS_URL", nil))
|
16
|
-
@redis =
|
18
|
+
@redis = if redis_url
|
19
|
+
Strum::Cache.config.redis_class.new(url: redis_url)
|
20
|
+
else
|
21
|
+
Strum::Cache.config.redis_class.new
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end)
|
19
25
|
end
|
26
|
+
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
@@ -5,19 +5,12 @@ require "json"
|
|
5
5
|
|
6
6
|
module Strum
|
7
7
|
module CacheUtils
|
8
|
+
# Send request to entity source
|
8
9
|
class SendRequest
|
9
10
|
include Strum::Service
|
10
11
|
|
11
12
|
def call
|
12
|
-
|
13
|
-
conn = Faraday.new(url: url)
|
14
|
-
resp = conn.get do |req|
|
15
|
-
req.params = params if input[:params]
|
16
|
-
req.headers["Content-Type"] = "application/json"
|
17
|
-
req.headers["Accept"] = "application/json"
|
18
|
-
cache_headers.each { |k, v| req.headers[k] = v }
|
19
|
-
end
|
20
|
-
resp.success? && output(JSON.parse(resp.body))
|
13
|
+
(resp = send_request).success? && output(JSON.parse(resp.body))
|
21
14
|
rescue Faraday::Error => e
|
22
15
|
add_error(:connection, e)
|
23
16
|
rescue JSON::JSONError => e
|
@@ -27,6 +20,25 @@ module Strum
|
|
27
20
|
def audit
|
28
21
|
required :url
|
29
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def cache_headers
|
27
|
+
Strum::Cache.config.cache_headers.is_a?(Hash) ? Strum::Cache.config.cache_headers : {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def conn
|
31
|
+
Faraday.new(url: url)
|
32
|
+
end
|
33
|
+
|
34
|
+
def send_request
|
35
|
+
conn.get do |req|
|
36
|
+
req.params = params if input[:params]
|
37
|
+
req.headers["Content-Type"] = "application/json"
|
38
|
+
req.headers["Accept"] = "application/json"
|
39
|
+
cache_headers.each { |k, v| req.headers[k] = v }
|
40
|
+
end
|
41
|
+
end
|
30
42
|
end
|
31
43
|
end
|
32
44
|
end
|
data/strum-cache.gemspec
CHANGED
@@ -9,14 +9,14 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["sn@nazarov.com.ua"]
|
10
10
|
|
11
11
|
spec.summary = "Cache resources"
|
12
|
-
spec.homepage = "https://
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
12
|
+
spec.homepage = "https://gitlab.com/strum-rb/strum-cache"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
14
14
|
|
15
15
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
-
spec.metadata["source_code_uri"] = "https://
|
19
|
-
spec.metadata["changelog_uri"] = "https://
|
18
|
+
spec.metadata["source_code_uri"] = "https://gitlab.com/strum-rb/strum-cache"
|
19
|
+
spec.metadata["changelog_uri"] = "https://gitlab.com/strum-rb/strum-cache/CHANGELOG.md"
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -32,5 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_dependency "faraday", "~> 1.1"
|
33
33
|
spec.add_dependency "json", "~> 2.3"
|
34
34
|
spec.add_dependency "redis", "~> 4.2"
|
35
|
-
spec.add_dependency "strum"
|
35
|
+
spec.add_dependency "strum-json", "~> 0.0.2"
|
36
|
+
spec.add_dependency "strum-pipe", "~> 0.0.3"
|
37
|
+
spec.add_dependency "strum-service", "~> 0.1"
|
36
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strum-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serhiy Nazarov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -81,19 +81,47 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '4.2'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: strum
|
84
|
+
name: strum-json
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.2
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: strum-pipe
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: 0.0.3
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.0.3
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: strum-service
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.1'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
124
|
+
version: '0.1'
|
97
125
|
description:
|
98
126
|
email:
|
99
127
|
- sn@nazarov.com.ua
|
@@ -102,6 +130,7 @@ extensions: []
|
|
102
130
|
extra_rdoc_files: []
|
103
131
|
files:
|
104
132
|
- ".gitignore"
|
133
|
+
- ".gitlab-ci.yml"
|
105
134
|
- ".rspec"
|
106
135
|
- ".rubocop.yml"
|
107
136
|
- ".travis.yml"
|
@@ -123,13 +152,13 @@ files:
|
|
123
152
|
- lib/strum/cache_utils/search.rb
|
124
153
|
- lib/strum/cache_utils/send_request.rb
|
125
154
|
- strum-cache.gemspec
|
126
|
-
homepage: https://
|
155
|
+
homepage: https://gitlab.com/strum-rb/strum-cache
|
127
156
|
licenses: []
|
128
157
|
metadata:
|
129
158
|
allowed_push_host: https://rubygems.org
|
130
|
-
homepage_uri: https://
|
131
|
-
source_code_uri: https://
|
132
|
-
changelog_uri: https://
|
159
|
+
homepage_uri: https://gitlab.com/strum-rb/strum-cache
|
160
|
+
source_code_uri: https://gitlab.com/strum-rb/strum-cache
|
161
|
+
changelog_uri: https://gitlab.com/strum-rb/strum-cache/CHANGELOG.md
|
133
162
|
post_install_message:
|
134
163
|
rdoc_options: []
|
135
164
|
require_paths:
|
@@ -138,14 +167,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
167
|
requirements:
|
139
168
|
- - ">="
|
140
169
|
- !ruby/object:Gem::Version
|
141
|
-
version: 2.
|
170
|
+
version: 2.7.0
|
142
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
172
|
requirements:
|
144
173
|
- - ">="
|
145
174
|
- !ruby/object:Gem::Version
|
146
175
|
version: '0'
|
147
176
|
requirements: []
|
148
|
-
rubygems_version: 3.1.
|
177
|
+
rubygems_version: 3.1.6
|
149
178
|
signing_key:
|
150
179
|
specification_version: 4
|
151
180
|
summary: Cache resources
|