minato-utils 0.2.1 → 0.3.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: 6bc10d814c0e9102aad2fc41b3f36ee3bf42e8e62221e855967c1e7839a98e80
4
- data.tar.gz: 0b1c1fbf289d59ff9db246f838c2ad46c625cd5990429af7e06ce4926aaf4db3
3
+ metadata.gz: a05b7abec99a94707b89712be193674bcca9a435659048c056bc35b1a2181388
4
+ data.tar.gz: 2c62d3651df6545e0246d6b0a3707a43c18e8754b3b870c49251783eef2929de
5
5
  SHA512:
6
- metadata.gz: 007ea958aecc24ddcf66c158100368763001981a5aa19e529f646e62f020fe17a12778e0587e3422d3690719868d23dca0ba91556ec31965c9b48ab75f9cbcec
7
- data.tar.gz: 55b48408b7cfa0d53ee20679edc8050f63bcefe13428e092e772b33f100ae890832e07de1dbca7b68761434b75eda50d23eb2a08e2cc145ce46663d32c2746a7
6
+ metadata.gz: b189685deee6144188542ca6a54aa3b5b30539c431b71c3a6ea39be4570df35f8a35a9f1441b0187ffeb22b5fa0a09b664f8bdbf0be25c058e9fb4a33f907395
7
+ data.tar.gz: 8be054f544d3820864763af19471edc40acf4077e795a97aa5dbcc7db41d6eb12a79779c309e1f586152de30638aa608b59194680a06a8019aacc49adb9bfcfc
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
2
  *.code-workspace
3
+ .rbenv-gemsets
data/.gitlab-ci.yml CHANGED
@@ -1,5 +1,2 @@
1
1
  include:
2
- - project: 'ferreri/minato-projects/minato-ci'
3
- ref: main
4
- file: '/gem/.gitlab-ci.yml'
5
-
2
+ - remote: 'https://gitlab.com/ferreri/minato/minato-ci/raw/main/gem/.gitlab-ci.yml'
data/Gemfile.lock CHANGED
@@ -1,13 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minato-utils (0.2.0)
4
+ minato-utils (0.3.0)
5
5
  activesupport (~> 6.0)
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:
12
+ activemodel (6.1.4.4)
13
+ activesupport (= 6.1.4.4)
14
+ activerecord (6.1.4.4)
15
+ activemodel (= 6.1.4.4)
16
+ activesupport (= 6.1.4.4)
11
17
  activesupport (6.1.4.4)
12
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
19
  i18n (>= 1.6, < 2)
@@ -21,6 +27,10 @@ GEM
21
27
  concurrent-ruby (1.1.9)
22
28
  crack (0.4.5)
23
29
  rexml
30
+ database_cleaner-active_record (2.0.1)
31
+ activerecord (>= 5.a)
32
+ database_cleaner-core (~> 2.0.0)
33
+ database_cleaner-core (2.0.1)
24
34
  diff-lcs (1.4.4)
25
35
  hashdiff (1.0.1)
26
36
  httparty (0.20.0)
@@ -32,7 +42,7 @@ GEM
32
42
  method_source (1.0.0)
33
43
  mime-types (3.4.1)
34
44
  mime-types-data (~> 3.2015)
35
- mime-types-data (3.2021.1115)
45
+ mime-types-data (3.2022.0105)
36
46
  minitest (5.15.0)
37
47
  multi_xml (0.6.0)
38
48
  parallel (1.21.0)
@@ -80,6 +90,8 @@ GEM
80
90
  rubocop-rspec (2.6.0)
81
91
  rubocop (~> 1.19)
82
92
  ruby-progressbar (1.11.0)
93
+ simple_command (0.1.0)
94
+ sqlite3 (1.4.2)
83
95
  tzinfo (2.0.4)
84
96
  concurrent-ruby (~> 1.0)
85
97
  unicode-display_width (2.1.0)
@@ -90,10 +102,13 @@ GEM
90
102
  zeitwerk (2.5.1)
91
103
 
92
104
  PLATFORMS
105
+ x86_64-darwin-21
93
106
  x86_64-linux
94
107
 
95
108
  DEPENDENCIES
109
+ activerecord (~> 6.1.4)
96
110
  bundler (~> 2.2)
111
+ database_cleaner-active_record (~> 2.0.1)
97
112
  json (~> 2.6)
98
113
  minato-utils!
99
114
  pry (~> 0.14)
@@ -103,7 +118,8 @@ DEPENDENCIES
103
118
  rubocop-rails (~> 2.12.4)
104
119
  rubocop-rake (~> 0.6.0)
105
120
  rubocop-rspec (~> 2.6.0)
121
+ sqlite3 (~> 1.4.2)
106
122
  webmock (~> 3.14)
107
123
 
108
124
  BUNDLED WITH
109
- 2.2.33
125
+ 2.3.13
@@ -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
@@ -37,7 +37,6 @@ module Minato
37
37
  private
38
38
 
39
39
  def request(method, path, options)
40
- return_headers = options.delete(:return_headers)
41
40
  request_options = @default_options.deep_merge(options)
42
41
  url = Minato::Utils::Helpers.join_url(@base_uri, path)
43
42
 
@@ -45,7 +44,7 @@ module Minato
45
44
  response = self.class.send(method, url, request_options)
46
45
 
47
46
  Minato::Utils.logger.log_response(method, @base_uri, path, request_options, response)
48
- Minato::Utils::ResponseHandler.handle(response, return_headers)
47
+ Minato::Utils::ResponseHandler.handle(response)
49
48
  end
50
49
  end
51
50
  end
@@ -41,5 +41,7 @@ module Minato
41
41
  class Unauthorized < NetworkException; end
42
42
 
43
43
  class UnprocessableEntity < NetworkException; end
44
+
45
+ class UnknownException < SerializableException; end
44
46
  end
45
47
  end
@@ -7,20 +7,16 @@ module Minato
7
7
  module Utils
8
8
  class ResponseHandler
9
9
  class << self
10
- def handle(response, return_headers)
10
+ def handle(response)
11
11
  raise_exception(response) if response_error?(response)
12
12
 
13
- if return_headers
14
- { body: Minato::Utils::Helpers.parse_json(response.body), header: response.header }
15
- else
16
- Minato::Utils::Helpers.parse_json(response.body)
17
- end
13
+ body = Minato::Utils::Helpers.parse_json(response.body)
14
+ header = response.header.to_hash || {}
15
+ { body: body, header: header }
18
16
  end
19
17
 
20
18
  private
21
19
 
22
- SUCCESSFUL_RESPONSE_CODE = [200, 201, 204, 302].freeze
23
-
24
20
  EXCEPTION_HANDLERS_MAP = {
25
21
  400 => 'bad_request',
26
22
  401 => 'unauthorized',
@@ -35,7 +31,7 @@ module Minato
35
31
  }.freeze
36
32
 
37
33
  def response_error?(response)
38
- SUCCESSFUL_RESPONSE_CODE.exclude?(response.code)
34
+ response.code >= 400
39
35
  end
40
36
 
41
37
  def raise_exception(response)
@@ -43,7 +39,8 @@ module Minato
43
39
  end
44
40
 
45
41
  def get_exception_class_from(code)
46
- "Minato::Utils::#{EXCEPTION_HANDLERS_MAP[code].camelize}".constantize
42
+ exception_name = EXCEPTION_HANDLERS_MAP[code] || 'unknown_exception'
43
+ "Minato::Utils::#{exception_name.camelize}".constantize
47
44
  end
48
45
  end
49
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minato
4
4
  module Utils
5
- VERSION = '0.2.1'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
data/lib/minato/utils.rb CHANGED
@@ -5,6 +5,7 @@ require_relative 'utils/exception'
5
5
  require_relative 'utils/helpers'
6
6
  require_relative 'utils/logger'
7
7
  require_relative 'utils/version'
8
+ require_relative 'utils/base_command/base'
8
9
 
9
10
  module Minato
10
11
  module Utils
@@ -26,8 +26,11 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency 'activesupport', '~> 6.0'
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', '~> 6.1.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 = {
data/release-notes.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Release Notes
2
2
 
3
+ ## v0.2.2 - January 4th, 2022
4
+
5
+ ### Compatibility Notes
6
+
7
+ - `return_headers` was removed from method `Minato::Utils::Client#request`<br/>
8
+ This renders `return_headers` as a hash key to `options` variable worthless, so
9
+ from now on you can assume that all requests will return a header regardless if
10
+ it's useful for the current invocation or not.
11
+
3
12
  ## v0.2.0 - December 20th, 2021
4
13
 
5
14
  ### Compatibility Notes
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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferreri
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-29 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -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: 6.1.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 6.1.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,6 +253,14 @@ 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