minato-utils 0.2.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +26 -11
- data/lib/minato/utils/base_command/base.rb +10 -0
- data/lib/minato/utils/base_command/create.rb +20 -0
- data/lib/minato/utils/base_command/destroy.rb +19 -0
- data/lib/minato/utils/base_command/index.rb +22 -0
- data/lib/minato/utils/base_command/nested_scoped_index.rb +22 -0
- data/lib/minato/utils/base_command/show.rb +20 -0
- data/lib/minato/utils/base_command/show_by.rb +21 -0
- data/lib/minato/utils/base_command/update.rb +21 -0
- data/lib/minato/utils/exception.rb +2 -0
- data/lib/minato/utils/response.rb +15 -0
- data/lib/minato/utils/response_handler.rb +4 -8
- data/lib/minato/utils/version.rb +1 -1
- data/lib/minato/utils.rb +2 -0
- data/minato-ruby-utils.gemspec +5 -1
- metadata +69 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a8780ff0c7c10c83e68eeb49c4196c3eeb1aa7c257b09aac2d07bf92a6aa38
|
4
|
+
data.tar.gz: 351586a3040d8a0b23f3cf4c0b7660325ce69bf45d7decba22c3ee98cc6e9afa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 815edaaf1d439b7b3c42baabc00374544c12fcdf14ce8b6e0b2e11426525d061635aca8b2536fd815a77efe70802947d177c20686e8bc91f7486a553a1b1048c
|
7
|
+
data.tar.gz: 7d24d96cf10fbea8ccf237acb44232993dfcc7224ee8bcff07ec4f5431869562e04ce0a03f54874dde20fcc36f86738a6a5817875056795b3170c7d51083eff3
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,39 +1,48 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
minato-utils (0.
|
5
|
-
activesupport (~>
|
4
|
+
minato-utils (0.4.0)
|
5
|
+
activesupport (~> 7.0.4)
|
6
6
|
httparty (~> 0.18)
|
7
|
+
simple_command (~> 0.1.0)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
11
|
-
|
12
|
+
activemodel (7.0.4)
|
13
|
+
activesupport (= 7.0.4)
|
14
|
+
activerecord (7.0.4)
|
15
|
+
activemodel (= 7.0.4)
|
16
|
+
activesupport (= 7.0.4)
|
17
|
+
activesupport (7.0.4)
|
12
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
19
|
i18n (>= 1.6, < 2)
|
14
20
|
minitest (>= 5.1)
|
15
21
|
tzinfo (~> 2.0)
|
16
|
-
zeitwerk (~> 2.3)
|
17
22
|
addressable (2.8.0)
|
18
23
|
public_suffix (>= 2.0.2, < 5.0)
|
19
24
|
ast (2.4.2)
|
20
25
|
coderay (1.1.3)
|
21
|
-
concurrent-ruby (1.1.
|
26
|
+
concurrent-ruby (1.1.10)
|
22
27
|
crack (0.4.5)
|
23
28
|
rexml
|
29
|
+
database_cleaner-active_record (2.0.1)
|
30
|
+
activerecord (>= 5.a)
|
31
|
+
database_cleaner-core (~> 2.0.0)
|
32
|
+
database_cleaner-core (2.0.1)
|
24
33
|
diff-lcs (1.4.4)
|
25
34
|
hashdiff (1.0.1)
|
26
35
|
httparty (0.20.0)
|
27
36
|
mime-types (~> 3.0)
|
28
37
|
multi_xml (>= 0.5.2)
|
29
|
-
i18n (1.
|
38
|
+
i18n (1.12.0)
|
30
39
|
concurrent-ruby (~> 1.0)
|
31
40
|
json (2.6.1)
|
32
41
|
method_source (1.0.0)
|
33
42
|
mime-types (3.4.1)
|
34
43
|
mime-types-data (~> 3.2015)
|
35
|
-
mime-types-data (3.
|
36
|
-
minitest (5.
|
44
|
+
mime-types-data (3.2022.0105)
|
45
|
+
minitest (5.16.3)
|
37
46
|
multi_xml (0.6.0)
|
38
47
|
parallel (1.21.0)
|
39
48
|
parser (3.0.3.2)
|
@@ -80,20 +89,25 @@ GEM
|
|
80
89
|
rubocop-rspec (2.6.0)
|
81
90
|
rubocop (~> 1.19)
|
82
91
|
ruby-progressbar (1.11.0)
|
83
|
-
|
92
|
+
simple_command (0.1.0)
|
93
|
+
sqlite3 (1.4.2)
|
94
|
+
tzinfo (2.0.5)
|
84
95
|
concurrent-ruby (~> 1.0)
|
85
96
|
unicode-display_width (2.1.0)
|
86
97
|
webmock (3.14.0)
|
87
98
|
addressable (>= 2.8.0)
|
88
99
|
crack (>= 0.3.2)
|
89
100
|
hashdiff (>= 0.4.0, < 2.0.0)
|
90
|
-
zeitwerk (2.5.1)
|
91
101
|
|
92
102
|
PLATFORMS
|
103
|
+
x64-mingw32
|
104
|
+
x86_64-darwin-21
|
93
105
|
x86_64-linux
|
94
106
|
|
95
107
|
DEPENDENCIES
|
108
|
+
activerecord (~> 7.0.4)
|
96
109
|
bundler (~> 2.2)
|
110
|
+
database_cleaner-active_record (~> 2.0.1)
|
97
111
|
json (~> 2.6)
|
98
112
|
minato-utils!
|
99
113
|
pry (~> 0.14)
|
@@ -103,7 +117,8 @@ DEPENDENCIES
|
|
103
117
|
rubocop-rails (~> 2.12.4)
|
104
118
|
rubocop-rake (~> 0.6.0)
|
105
119
|
rubocop-rspec (~> 2.6.0)
|
120
|
+
sqlite3 (~> 1.4.2)
|
106
121
|
webmock (~> 3.14)
|
107
122
|
|
108
123
|
BUNDLED WITH
|
109
|
-
2.
|
124
|
+
2.3.25
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simple_command'
|
4
|
+
require_relative 'create'
|
5
|
+
require_relative 'destroy'
|
6
|
+
require_relative 'index'
|
7
|
+
require_relative 'nested_scoped_index'
|
8
|
+
require_relative 'show'
|
9
|
+
require_relative 'show_by'
|
10
|
+
require_relative 'update'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Utils
|
5
|
+
module BaseCommand
|
6
|
+
class Create
|
7
|
+
prepend SimpleCommand
|
8
|
+
|
9
|
+
def initialize(model_class, params)
|
10
|
+
@model_class = model_class
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
@model_class.send :create!, @params
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Utils
|
5
|
+
module BaseCommand
|
6
|
+
class Destroy
|
7
|
+
prepend SimpleCommand
|
8
|
+
|
9
|
+
def initialize(model)
|
10
|
+
@model = model
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
@model.destroy!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Utils
|
5
|
+
module BaseCommand
|
6
|
+
class Index
|
7
|
+
prepend SimpleCommand
|
8
|
+
|
9
|
+
def initialize(model_class, filters = {})
|
10
|
+
@model_class = model_class
|
11
|
+
@filters = filters
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
return @model_class.where(@filters) if @filters.present?
|
16
|
+
|
17
|
+
@model_class.all
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Utils
|
5
|
+
module BaseCommand
|
6
|
+
class NestedScopedIndex
|
7
|
+
prepend SimpleCommand
|
8
|
+
|
9
|
+
def initialize(scope, context, model_class, parent_id)
|
10
|
+
@scope = scope
|
11
|
+
@context = context
|
12
|
+
@model_class = model_class
|
13
|
+
@parent_id = parent_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
@scope.new(@context, @model_class, @parent_id).resolve
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Utils
|
5
|
+
module BaseCommand
|
6
|
+
class Show
|
7
|
+
prepend SimpleCommand
|
8
|
+
|
9
|
+
def initialize(model_class, id)
|
10
|
+
@model_class = model_class
|
11
|
+
@id = id
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
@model_class.send :find, @id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Utils
|
5
|
+
module BaseCommand
|
6
|
+
class ShowBy
|
7
|
+
prepend SimpleCommand
|
8
|
+
|
9
|
+
def initialize(model_class, attribute, value)
|
10
|
+
@model_class = model_class
|
11
|
+
@attribute = attribute
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
@model_class.send :find_by!, @attribute => @value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Utils
|
5
|
+
module BaseCommand
|
6
|
+
class Update
|
7
|
+
prepend SimpleCommand
|
8
|
+
|
9
|
+
def initialize(model, params)
|
10
|
+
@model = model
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
@model.update!(@params)
|
16
|
+
@model
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minato
|
4
|
+
module Utils
|
5
|
+
class Response
|
6
|
+
attr_reader :code, :header, :body
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@code = response.code
|
10
|
+
@header = response.header.to_hash || {}
|
11
|
+
@body = Helpers.parse_json(response.body)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -9,16 +9,11 @@ module Minato
|
|
9
9
|
class << self
|
10
10
|
def handle(response)
|
11
11
|
raise_exception(response) if response_error?(response)
|
12
|
-
|
13
|
-
body = Minato::Utils::Helpers.parse_json(response.body)
|
14
|
-
header = response.header.to_hash || {}
|
15
|
-
{ body: body, header: header }
|
12
|
+
Response.new(response)
|
16
13
|
end
|
17
14
|
|
18
15
|
private
|
19
16
|
|
20
|
-
SUCCESSFUL_RESPONSE_CODE = [200, 201, 204, 302, 303].freeze
|
21
|
-
|
22
17
|
EXCEPTION_HANDLERS_MAP = {
|
23
18
|
400 => 'bad_request',
|
24
19
|
401 => 'unauthorized',
|
@@ -33,7 +28,7 @@ module Minato
|
|
33
28
|
}.freeze
|
34
29
|
|
35
30
|
def response_error?(response)
|
36
|
-
|
31
|
+
response.code >= 400
|
37
32
|
end
|
38
33
|
|
39
34
|
def raise_exception(response)
|
@@ -41,7 +36,8 @@ module Minato
|
|
41
36
|
end
|
42
37
|
|
43
38
|
def get_exception_class_from(code)
|
44
|
-
|
39
|
+
exception_name = EXCEPTION_HANDLERS_MAP[code] || 'unknown_exception'
|
40
|
+
"Minato::Utils::#{exception_name.camelize}".constantize
|
45
41
|
end
|
46
42
|
end
|
47
43
|
end
|
data/lib/minato/utils/version.rb
CHANGED
data/lib/minato/utils.rb
CHANGED
data/minato-ruby-utils.gemspec
CHANGED
@@ -24,10 +24,13 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
|
-
spec.add_dependency 'activesupport', '~>
|
27
|
+
spec.add_dependency 'activesupport', '~> 7.0.4'
|
28
28
|
spec.add_dependency 'httparty', '~> 0.18'
|
29
|
+
spec.add_dependency 'simple_command', '~> 0.1.0'
|
29
30
|
|
31
|
+
spec.add_development_dependency 'activerecord', '~> 7.0.4'
|
30
32
|
spec.add_development_dependency 'bundler', '~> 2.2'
|
33
|
+
spec.add_development_dependency 'database_cleaner-active_record', '~> 2.0.1'
|
31
34
|
spec.add_development_dependency 'json', '~> 2.6'
|
32
35
|
spec.add_development_dependency 'pry', '~> 0.14'
|
33
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -36,6 +39,7 @@ Gem::Specification.new do |spec|
|
|
36
39
|
spec.add_development_dependency 'rubocop-rails', '~> 2.12.4'
|
37
40
|
spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
38
41
|
spec.add_development_dependency 'rubocop-rspec', '~> 2.6.0'
|
42
|
+
spec.add_development_dependency 'sqlite3', '~> 1.4.2'
|
39
43
|
spec.add_development_dependency 'webmock', '~> 3.14'
|
40
44
|
|
41
45
|
spec.metadata = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minato-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ferreri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.0.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 7.0.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: httparty
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.18'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simple_command
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 7.0.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 7.0.4
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: bundler
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +80,20 @@ dependencies:
|
|
52
80
|
- - "~>"
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '2.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: database_cleaner-active_record
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.0.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.0.1
|
55
97
|
- !ruby/object:Gem::Dependency
|
56
98
|
name: json
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +206,20 @@ dependencies:
|
|
164
206
|
- - "~>"
|
165
207
|
- !ruby/object:Gem::Version
|
166
208
|
version: 2.6.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: sqlite3
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 1.4.2
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 1.4.2
|
167
223
|
- !ruby/object:Gem::Dependency
|
168
224
|
name: webmock
|
169
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -197,11 +253,20 @@ files:
|
|
197
253
|
- bin/console
|
198
254
|
- bin/setup
|
199
255
|
- lib/minato/utils.rb
|
256
|
+
- lib/minato/utils/base_command/base.rb
|
257
|
+
- lib/minato/utils/base_command/create.rb
|
258
|
+
- lib/minato/utils/base_command/destroy.rb
|
259
|
+
- lib/minato/utils/base_command/index.rb
|
260
|
+
- lib/minato/utils/base_command/nested_scoped_index.rb
|
261
|
+
- lib/minato/utils/base_command/show.rb
|
262
|
+
- lib/minato/utils/base_command/show_by.rb
|
263
|
+
- lib/minato/utils/base_command/update.rb
|
200
264
|
- lib/minato/utils/client.rb
|
201
265
|
- lib/minato/utils/configuration.rb
|
202
266
|
- lib/minato/utils/exception.rb
|
203
267
|
- lib/minato/utils/helpers.rb
|
204
268
|
- lib/minato/utils/logger.rb
|
269
|
+
- lib/minato/utils/response.rb
|
205
270
|
- lib/minato/utils/response_handler.rb
|
206
271
|
- lib/minato/utils/version.rb
|
207
272
|
- minato-ruby-utils.gemspec
|