console_utils 0.9.0 → 0.10.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: '09a3c963c0f381509271a6f9598e6546cefd3ae48fed7dbe0b753f96b24b6eac'
4
- data.tar.gz: 10ab073e39883263b7053d6709c47351c6f858befe278574f14338a9c29a7bab
3
+ metadata.gz: a398186f93724b6e079f8443d514f2e509c68cff8b2f30194538369007278818
4
+ data.tar.gz: 73897b3d111dd2faaa0a53a20f89a2bff7ef7a7e14752ff46ce33bc942218f84
5
5
  SHA512:
6
- metadata.gz: 320d84f01062d96ca794a77e6fa568e9e9d26bc255c13986b2f17cba51199471bf4f48724d6d201baf479c2c093e0f6dc6301241b4a5a2b6fd5da579e6b5e8a2
7
- data.tar.gz: 2b1d9fc87d8492976646a6ef0521ec1728b74fe7f4a488a412871fac73e44cee81bd05d3e6b61beeabade0085d46b7dcb7f19e99f6140499d18cdd1c17cbff5c
6
+ metadata.gz: 94d282e685e0cda6ca1ab63dad2a647f4b39b9ac26800caef074988315e6230626315c3b12c8a8e9be6245a598412bedd2d9fdfcf476e64d92c7711201219434
7
+ data.tar.gz: 857a57629b1fd1ab6ab855f0b8dc3ac7a4349b1def0729359e9439efe9c1c75cb1d6f1156d41ea8eb19b36a4f0ae1eafa7e4ab886e4e7bedc72cc6ff0fa1e4b2
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
  spec.required_ruby_version = ">= 2.1"
22
22
 
23
- spec.add_dependency "activesupport", ">= 4.1", "< 7"
23
+ spec.add_dependency "activesupport", ">= 5.2", "< 7"
24
24
  spec.add_dependency "pastel"
25
25
  spec.add_dependency "awesome_print"
26
26
  spec.add_dependency "benchmark-ips"
@@ -140,6 +140,12 @@ module ConsoleUtils
140
140
  # which is useful when using the +simple_token_automator+ gem.
141
141
  mattr_accessor(:auth_automator) { ConsoleUtils::RequestUtils::DefaultAuthAutomator }
142
142
 
143
+ # :attr:
144
+ # Keeps any amount of callable objects to invoke them before each request,
145
+ # with an instance of <tt>ConsoleUtils::RequestUtils::RequestParams</tt>
146
+ # as only the argument.
147
+ # (default: <tt>[]</tt>)
148
+ mattr_accessor(:request_hooks) { [] }
143
149
 
144
150
  # :section: Class Methods
145
151
 
@@ -9,7 +9,7 @@ module ConsoleUtils::RequestUtils #:nodoc:
9
9
  def #{request_method}(url, *args)
10
10
  @url = url
11
11
  @_args = args
12
- app.request_via_redirect(:#{request_method}, @url, *normalize_args.to_a)
12
+ app.process(:#{request_method}, @url, **normalize_args.to_h)
13
13
  self
14
14
  end
15
15
  RUBY
@@ -1,29 +1,23 @@
1
- module ConsoleUtils::RequestUtils
2
- class RequestParams
3
- attr_accessor :uid
1
+ # frozen_string_literal: true
4
2
 
5
- def initialize(uid_or_params = true, params = nil, headers = nil)
6
- # puts "Request params: uid_or_params=#{uid_or_params} | params=#{params} | headers=#{headers}"
7
-
8
- if uid_or_params.is_a? Hash
9
- headers, params, uid_or_params = [params, uid_or_params, nil]
10
- end
11
-
12
- @params = params if params
13
- @headers = headers if headers
14
- @uid = auto_auth? && ((uid_or_params.nil? || uid_or_params == true) ? ConsoleUtils.default_uid : uid_or_params)
15
-
16
- ConsoleUtils.logger.debug { "#{uid}, #{params()}, #{headers()}" }
3
+ module ConsoleUtils::RequestUtils
4
+ RequestParams = Struct.new(:params, :headers)
17
5
 
18
- auth_automator.(self)
6
+ class RequestParams
7
+ AutoUid = -> (uid) do
8
+ ConsoleUtils.request_auto_auth && ((uid.nil? || uid == true) ? ConsoleUtils.default_uid : uid)
19
9
  end
20
10
 
21
- def params
22
- @params ||= {}
23
- end
11
+ attr_accessor :uid
24
12
 
25
- def headers
26
- @headers ||= {}
13
+ def initialize(uid = true, params = nil, headers = nil)
14
+ params, headers, uid = [uid, params, nil] if uid.is_a?(Hash)
15
+ @uid = AutoUid[uid] || uid
16
+ super(params.to_h, headers.to_h)
17
+
18
+ ConsoleUtils.auth_automator.(self) if ConsoleUtils.auth_automator.respond_to?(:call)
19
+ ConsoleUtils.request_hooks.each { |hook| hook.(self) }
20
+ ConsoleUtils.logger.debug { "#{@uid}, #{self}" }
27
21
  end
28
22
 
29
23
  def to_a
@@ -43,17 +37,7 @@ module ConsoleUtils::RequestUtils
43
37
  end
44
38
 
45
39
  def can_auto_auth?
46
- auto_auth? && uid && auth_automator.respond_to?(:call)
47
- end
48
-
49
- private
50
-
51
- def auto_auth?
52
- ConsoleUtils.request_auto_auth
53
- end
54
-
55
- def auth_automator
56
- ConsoleUtils.auth_automator
40
+ ConsoleUtils.request_auto_auth && @uid && ConsoleUtils.auth_automator.respond_to?(:call)
57
41
  end
58
42
  end
59
43
  end
@@ -1,3 +1,3 @@
1
1
  module ConsoleUtils
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-02 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '7'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.1'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '7'
@@ -193,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.7.6
196
+ rubygems_version: 3.0.3
198
197
  signing_key:
199
198
  specification_version: 4
200
199
  summary: Groovy tools for Rails Console.