console_utils 0.6.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -1
- data/Appraisals +6 -0
- data/README.md +1 -1
- data/console_utils.gemspec +2 -2
- data/gemfiles/rails42.gemfile.lock +2 -2
- data/gemfiles/rails5.gemfile +9 -0
- data/gemfiles/rails5.gemfile.lock +149 -0
- data/lib/console_utils.rb +11 -1
- data/lib/console_utils/active_record_utils.rb +1 -1
- data/lib/console_utils/active_record_utils/random_record.rb +10 -2
- data/lib/console_utils/other_utils.rb +2 -2
- data/lib/console_utils/request_utils/auth_automators.rb +0 -1
- data/lib/console_utils/request_utils/exap.rb +9 -6
- data/lib/console_utils/request_utils/remo.rb +117 -18
- data/lib/console_utils/request_utils/request_params.rb +17 -33
- data/lib/console_utils/request_utils/requester.rb +31 -11
- data/lib/console_utils/version.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a398186f93724b6e079f8443d514f2e509c68cff8b2f30194538369007278818
|
4
|
+
data.tar.gz: 73897b3d111dd2faaa0a53a20f89a2bff7ef7a7e14752ff46ce33bc942218f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d282e685e0cda6ca1ab63dad2a647f4b39b9ac26800caef074988315e6230626315c3b12c8a8e9be6245a598412bedd2d9fdfcf476e64d92c7711201219434
|
7
|
+
data.tar.gz: 857a57629b1fd1ab6ab855f0b8dc3ac7a4349b1def0729359e9439efe9c1c75cb1d6f1156d41ea8eb19b36a4f0ae1eafa7e4ab886e4e7bedc72cc6ff0fa1e4b2
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/README.md
CHANGED
@@ -184,7 +184,7 @@ Also provides shorthand to find any user by id: `usr(id)`
|
|
184
184
|
## OtherUtils
|
185
185
|
|
186
186
|
#### clr()
|
187
|
-
|
187
|
+
[Pastel](https://github.com/piotrmurach/pastel) shorthand
|
188
188
|
|
189
189
|
#### shutting(:engine_key[, to: logger_level]) {}
|
190
190
|
Shuts up the logger of a specified Rails engine for a given key (`:rails`, `:record`, `:controller` or `:view`).
|
data/console_utils.gemspec
CHANGED
@@ -20,8 +20,8 @@ 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", ">=
|
24
|
-
spec.add_dependency "
|
23
|
+
spec.add_dependency "activesupport", ">= 5.2", "< 7"
|
24
|
+
spec.add_dependency "pastel"
|
25
25
|
spec.add_dependency "awesome_print"
|
26
26
|
spec.add_dependency "benchmark-ips"
|
27
27
|
spec.add_dependency "pry-rails"
|
@@ -0,0 +1,149 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
console_utils (0.6.1)
|
5
|
+
activesupport (>= 4.1, < 6)
|
6
|
+
awesome_print
|
7
|
+
benchmark-ips
|
8
|
+
pry-rails
|
9
|
+
term-ansicolor
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
actioncable (5.0.0)
|
15
|
+
actionpack (= 5.0.0)
|
16
|
+
nio4r (~> 1.2)
|
17
|
+
websocket-driver (~> 0.6.1)
|
18
|
+
actionmailer (5.0.0)
|
19
|
+
actionpack (= 5.0.0)
|
20
|
+
actionview (= 5.0.0)
|
21
|
+
activejob (= 5.0.0)
|
22
|
+
mail (~> 2.5, >= 2.5.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
actionpack (5.0.0)
|
25
|
+
actionview (= 5.0.0)
|
26
|
+
activesupport (= 5.0.0)
|
27
|
+
rack (~> 2.0)
|
28
|
+
rack-test (~> 0.6.3)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
31
|
+
actionview (5.0.0)
|
32
|
+
activesupport (= 5.0.0)
|
33
|
+
builder (~> 3.1)
|
34
|
+
erubis (~> 2.7.0)
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
37
|
+
activejob (5.0.0)
|
38
|
+
activesupport (= 5.0.0)
|
39
|
+
globalid (>= 0.3.6)
|
40
|
+
activemodel (5.0.0)
|
41
|
+
activesupport (= 5.0.0)
|
42
|
+
activerecord (5.0.0)
|
43
|
+
activemodel (= 5.0.0)
|
44
|
+
activesupport (= 5.0.0)
|
45
|
+
arel (~> 7.0)
|
46
|
+
activesupport (5.0.0)
|
47
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
48
|
+
i18n (~> 0.7)
|
49
|
+
minitest (~> 5.1)
|
50
|
+
tzinfo (~> 1.1)
|
51
|
+
appraisal (2.1.0)
|
52
|
+
bundler
|
53
|
+
rake
|
54
|
+
thor (>= 0.14.0)
|
55
|
+
arel (7.1.1)
|
56
|
+
awesome_print (1.7.0)
|
57
|
+
benchmark-ips (2.7.0)
|
58
|
+
builder (3.2.2)
|
59
|
+
coderay (1.1.1)
|
60
|
+
concurrent-ruby (1.0.2)
|
61
|
+
erubis (2.7.0)
|
62
|
+
globalid (0.3.7)
|
63
|
+
activesupport (>= 4.1.0)
|
64
|
+
i18n (0.7.0)
|
65
|
+
json (1.8.3)
|
66
|
+
loofah (2.0.3)
|
67
|
+
nokogiri (>= 1.5.9)
|
68
|
+
mail (2.6.4)
|
69
|
+
mime-types (>= 1.16, < 4)
|
70
|
+
method_source (0.8.2)
|
71
|
+
mime-types (3.1)
|
72
|
+
mime-types-data (~> 3.2015)
|
73
|
+
mime-types-data (3.2016.0521)
|
74
|
+
mini_portile2 (2.1.0)
|
75
|
+
minitest (5.9.0)
|
76
|
+
nio4r (1.2.1)
|
77
|
+
nokogiri (1.6.8)
|
78
|
+
mini_portile2 (~> 2.1.0)
|
79
|
+
pkg-config (~> 1.1.7)
|
80
|
+
pkg-config (1.1.7)
|
81
|
+
pry (0.10.4)
|
82
|
+
coderay (~> 1.1.0)
|
83
|
+
method_source (~> 0.8.1)
|
84
|
+
slop (~> 3.4)
|
85
|
+
pry-rails (0.3.4)
|
86
|
+
pry (>= 0.9.10)
|
87
|
+
rack (2.0.1)
|
88
|
+
rack-test (0.6.3)
|
89
|
+
rack (>= 1.0)
|
90
|
+
rails (5.0.0)
|
91
|
+
actioncable (= 5.0.0)
|
92
|
+
actionmailer (= 5.0.0)
|
93
|
+
actionpack (= 5.0.0)
|
94
|
+
actionview (= 5.0.0)
|
95
|
+
activejob (= 5.0.0)
|
96
|
+
activemodel (= 5.0.0)
|
97
|
+
activerecord (= 5.0.0)
|
98
|
+
activesupport (= 5.0.0)
|
99
|
+
bundler (>= 1.3.0, < 2.0)
|
100
|
+
railties (= 5.0.0)
|
101
|
+
sprockets-rails (>= 2.0.0)
|
102
|
+
rails-dom-testing (2.0.1)
|
103
|
+
activesupport (>= 4.2.0, < 6.0)
|
104
|
+
nokogiri (~> 1.6.0)
|
105
|
+
rails-html-sanitizer (1.0.3)
|
106
|
+
loofah (~> 2.0)
|
107
|
+
railties (5.0.0)
|
108
|
+
actionpack (= 5.0.0)
|
109
|
+
activesupport (= 5.0.0)
|
110
|
+
method_source
|
111
|
+
rake (>= 0.8.7)
|
112
|
+
thor (>= 0.18.1, < 2.0)
|
113
|
+
rake (11.2.2)
|
114
|
+
rdoc (4.2.2)
|
115
|
+
json (~> 1.4)
|
116
|
+
slop (3.6.0)
|
117
|
+
sprockets (3.7.0)
|
118
|
+
concurrent-ruby (~> 1.0)
|
119
|
+
rack (> 1, < 3)
|
120
|
+
sprockets-rails (3.1.1)
|
121
|
+
actionpack (>= 4.0)
|
122
|
+
activesupport (>= 4.0)
|
123
|
+
sprockets (>= 3.0.0)
|
124
|
+
sqlite3 (1.3.11)
|
125
|
+
term-ansicolor (1.3.2)
|
126
|
+
tins (~> 1.0)
|
127
|
+
thor (0.19.1)
|
128
|
+
thread_safe (0.3.5)
|
129
|
+
tins (1.12.0)
|
130
|
+
tzinfo (1.2.2)
|
131
|
+
thread_safe (~> 0.1)
|
132
|
+
websocket-driver (0.6.4)
|
133
|
+
websocket-extensions (>= 0.1.0)
|
134
|
+
websocket-extensions (0.1.2)
|
135
|
+
|
136
|
+
PLATFORMS
|
137
|
+
ruby
|
138
|
+
|
139
|
+
DEPENDENCIES
|
140
|
+
appraisal
|
141
|
+
console_utils!
|
142
|
+
minitest
|
143
|
+
pry-rails
|
144
|
+
rails (~> 5)
|
145
|
+
rdoc
|
146
|
+
sqlite3
|
147
|
+
|
148
|
+
BUNDLED WITH
|
149
|
+
1.12.5
|
data/lib/console_utils.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/core_ext'
|
3
3
|
require 'active_support/tagged_logging'
|
4
|
-
require '
|
4
|
+
require 'pastel'
|
5
5
|
require 'console_utils/core_ext/array_to_proc'
|
6
6
|
require 'console_utils/core_ext/local_values'
|
7
7
|
require 'console_utils/version'
|
@@ -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
|
|
@@ -201,6 +207,10 @@ module ConsoleUtils
|
|
201
207
|
def setup_modules_to(context = nil)
|
202
208
|
ReplState.setup(context)
|
203
209
|
end
|
210
|
+
|
211
|
+
def pastel
|
212
|
+
@pastel ||= Pastel.new
|
213
|
+
end
|
204
214
|
end
|
205
215
|
|
206
216
|
ActiveSupport.run_load_hooks(:console_utils, self)
|
@@ -6,7 +6,7 @@ module ConsoleUtils #:nodoc:
|
|
6
6
|
|
7
7
|
def self.extended(mod)
|
8
8
|
ActiveSupport.on_load(:active_record) do
|
9
|
-
ActiveRecord::Relation.send(:
|
9
|
+
ActiveRecord::Relation.send(:prepend, RandomRecord::FinderMethods)
|
10
10
|
ActiveRecord::Base.send(:extend, RandomRecord::Querying)
|
11
11
|
end
|
12
12
|
end
|
@@ -9,8 +9,16 @@ module ConsoleUtils::ActiveRecordUtils #:nodoc:
|
|
9
9
|
random.first
|
10
10
|
end
|
11
11
|
|
12
|
-
def anyid
|
13
|
-
|
12
|
+
def anyid(n = nil)
|
13
|
+
if n
|
14
|
+
@_anyid_history[-n.abs].presence || anyid()
|
15
|
+
else
|
16
|
+
idval = connection.select_value(select(:id).random.limit(1))
|
17
|
+
model.type_for_attribute('id').send(:cast_value, idval).tap do |result|
|
18
|
+
(@_anyid_history ||= []) << result
|
19
|
+
@_anyid_history.shift if @_anyid_history.size > 10
|
20
|
+
end
|
21
|
+
end
|
14
22
|
end
|
15
23
|
end
|
16
24
|
|
@@ -4,12 +4,15 @@ module ConsoleUtils::RequestUtils #:nodoc:
|
|
4
4
|
class Exap < Requester
|
5
5
|
INSPECT_FORMAT = "<Local: %s (%s)>".freeze
|
6
6
|
|
7
|
-
ConsoleUtils.request_methods.each do |
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
ConsoleUtils.request_methods.each do |request_method|
|
8
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
9
|
+
def #{request_method}(url, *args)
|
10
|
+
@url = url
|
11
|
+
@_args = args
|
12
|
+
app.process(:#{request_method}, @url, **normalize_args.to_h)
|
13
|
+
self
|
14
|
+
end
|
15
|
+
RUBY
|
13
16
|
end
|
14
17
|
|
15
18
|
def to_s
|
@@ -1,21 +1,25 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require
|
2
|
+
require 'open3'
|
3
|
+
require 'shellwords'
|
4
|
+
require 'console_utils/request_utils/requester'
|
3
5
|
|
4
6
|
module ConsoleUtils::RequestUtils #:nodoc:
|
5
7
|
class Remo < Requester
|
6
|
-
OUT_FORMAT = "\n%{size_download}\n%{time_total}".freeze
|
7
8
|
INSPECT_FORMAT = "<Remote: %s in %s ms>".freeze
|
8
9
|
INSPECT_NOTHING = "<Remote: nothing>".freeze
|
9
10
|
|
10
11
|
attr_reader :request_method
|
11
12
|
|
12
|
-
ConsoleUtils.request_methods.each do |
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
ConsoleUtils.request_methods.each do |request_method|
|
14
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
15
|
+
def #{request_method}(url, *args)
|
16
|
+
@_args = args
|
17
|
+
@request_method = "#{request_method.to_s.upcase}"
|
18
|
+
@request_params = normalize_args
|
19
|
+
@url = urlify(url, @request_params.params)
|
20
|
+
perform
|
21
|
+
end
|
22
|
+
RUBY
|
19
23
|
end
|
20
24
|
|
21
25
|
def inspect
|
@@ -30,30 +34,125 @@ module ConsoleUtils::RequestUtils #:nodoc:
|
|
30
34
|
@_body
|
31
35
|
end
|
32
36
|
|
37
|
+
attr_reader :_result
|
38
|
+
|
33
39
|
protected
|
34
40
|
|
35
41
|
def perform
|
36
|
-
|
42
|
+
data = @request_params.params.to_json unless params_to_query?
|
43
|
+
Curl.(request_method, url, data: data, headers: @request_params.headers) do |result, payload|
|
44
|
+
@_result = result
|
45
|
+
set_payload!(payload)
|
46
|
+
end
|
37
47
|
end
|
38
48
|
|
39
49
|
private
|
40
50
|
|
41
|
-
def set_payload!((*body_lines,
|
51
|
+
def set_payload!((*body_lines, code, time, size))
|
42
52
|
@_body = body_lines.join
|
53
|
+
@_code = code.to_i
|
43
54
|
@_size = size.to_f
|
44
55
|
@_time = time.tr(?,, ?.).to_f
|
45
56
|
self
|
46
57
|
end
|
47
58
|
|
48
|
-
def
|
49
|
-
|
50
|
-
tap { |
|
59
|
+
def urlify(path, options = nil)
|
60
|
+
URI.join(ConsoleUtils.remote_endpoint, path).
|
61
|
+
tap { |uri| uri.query = options.to_query if options && params_to_query? }.to_s
|
51
62
|
end
|
52
63
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
64
|
+
def params_to_query?
|
65
|
+
["GET", "HEAD"].include?(@request_method) || @request_method.headers["Content-Type"] != "application/json"
|
66
|
+
end
|
67
|
+
|
68
|
+
class Curl
|
69
|
+
OUT_FORMAT = '\n%{http_code}\n%{time_total}\n%{size_download}'.freeze
|
70
|
+
HEADER_JOIN_PROC = proc { |*kv| ["-H", kv.flatten.join(": ")] }
|
71
|
+
|
72
|
+
def self.call(*args)
|
73
|
+
result = new(*args)
|
74
|
+
yield(result.to_h, result.payload)
|
75
|
+
end
|
76
|
+
|
77
|
+
attr_reader :request, :response, :payload
|
78
|
+
|
79
|
+
def initialize(request_method, url, data: nil, headers: nil)
|
80
|
+
cmd = %W(#{ConsoleUtils.curl_bin} --silent -v -g)
|
81
|
+
cmd.push("-X#{request_method}")
|
82
|
+
cmd.push(url)
|
83
|
+
|
84
|
+
cmd.concat(headers.flat_map(&HEADER_JOIN_PROC)) if headers.present?
|
85
|
+
cmd.push("-d", data) if data.present?
|
86
|
+
|
87
|
+
cmd_line = Shellwords.join(cmd)
|
88
|
+
cmd_line << %( --write-out "#{OUT_FORMAT}")
|
89
|
+
|
90
|
+
puts "$ #{cmd_line}" if verbose?
|
91
|
+
|
92
|
+
@response = {}
|
93
|
+
@request = {}
|
94
|
+
@payload = []
|
95
|
+
|
96
|
+
Open3.popen3(cmd_line) do |stdin, stdout, stderr, thr|
|
97
|
+
# stdin.close
|
98
|
+
{ stderr: stderr, stdout: stdout }.each do |key, io|
|
99
|
+
Thread.new do
|
100
|
+
begin
|
101
|
+
until (line = io.gets).nil? do
|
102
|
+
key == :stderr ? process_stderr(line) : @payload << line
|
103
|
+
end
|
104
|
+
rescue => e
|
105
|
+
warn e
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
thr.join
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
KEY_MAP = { ">" => :request, "<" => :response }
|
114
|
+
|
115
|
+
def process_stderr(line)
|
116
|
+
# warn(line)
|
117
|
+
if type = KEY_MAP[line.chr]
|
118
|
+
line = line[2, line.size-1].strip
|
119
|
+
|
120
|
+
return if line.size == 0
|
121
|
+
|
122
|
+
case type
|
123
|
+
when :request; set_request(line)
|
124
|
+
when :response; set_response(line)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def set_request(line)
|
130
|
+
# warn("Request: #{line}")
|
131
|
+
if !@request.key?(:http_version) && line =~ /^(GET|POST|PUT|PATCH|HEAD|OPTION|DELETE) (.+?) HTTP\/(.+)$/
|
132
|
+
@request.merge!(method: $1, url: $2, http_version: $3)
|
133
|
+
else
|
134
|
+
header, value = line.split(": ", 2)
|
135
|
+
@request[header] = value
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def set_response(line)
|
140
|
+
# warn("Response: #{line}")
|
141
|
+
if !@response.key?(:http_version) && line =~ /^HTTP\/(.+) (\d+?) (.+)$/
|
142
|
+
@response.merge!(http_version: $1, http_code: $2.to_i, http_status: $3)
|
143
|
+
else
|
144
|
+
header, value = line.split(": ", 2)
|
145
|
+
@response[header] = value
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_h
|
150
|
+
{ response: @response, request: @request }
|
151
|
+
end
|
152
|
+
|
153
|
+
def verbose?
|
154
|
+
!ConsoleUtils.curl_silence
|
155
|
+
end
|
57
156
|
end
|
58
157
|
end
|
59
158
|
end
|
@@ -1,29 +1,23 @@
|
|
1
|
-
|
2
|
-
class RequestParams
|
3
|
-
attr_accessor :uid
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
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
|
-
|
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
|
-
|
22
|
-
@params ||= {}
|
23
|
-
end
|
11
|
+
attr_accessor :uid
|
24
12
|
|
25
|
-
def headers
|
26
|
-
|
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
|
@@ -39,21 +33,11 @@ module ConsoleUtils::RequestUtils
|
|
39
33
|
headers.merge!(default_headers.to_h)
|
40
34
|
end
|
41
35
|
|
42
|
-
|
36
|
+
self
|
43
37
|
end
|
44
38
|
|
45
39
|
def can_auto_auth?
|
46
|
-
|
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
|
@@ -5,10 +5,8 @@ module ConsoleUtils::RequestUtils #:nodoc:
|
|
5
5
|
class Requester < SimpleDelegator
|
6
6
|
INFO_HASH_FIELDS = %i(url size time human_size human_time).freeze
|
7
7
|
INFO_FORMAT = "%#-.50{url} | %#10{human_size} | %#10{human_time}\n".freeze
|
8
|
-
NO_RESPONSE =
|
9
|
-
PBCOPY_MESSAGE =
|
10
|
-
COMPLETE_IN = Term::ANSIColor.green("Complete in %s").freeze
|
11
|
-
TRANSFERED = Term::ANSIColor.cyan("Transfered: %s").freeze
|
8
|
+
NO_RESPONSE = ConsoleUtils.pastel.red(" \u27A7 Empty response's body.").freeze
|
9
|
+
PBCOPY_MESSAGE = ConsoleUtils.pastel.green(" \u27A4 Response body copied to pasteboard\n").freeze
|
12
10
|
|
13
11
|
class_attribute :default_params, instance_writer: false
|
14
12
|
attr_reader :url
|
@@ -54,33 +52,55 @@ module ConsoleUtils::RequestUtils #:nodoc:
|
|
54
52
|
end
|
55
53
|
|
56
54
|
def to_info_hash
|
57
|
-
|
55
|
+
hsh = {}
|
56
|
+
INFO_HASH_FIELDS.each { |field| hsh[field] = public_send(field) }
|
57
|
+
hsh
|
58
58
|
end
|
59
59
|
|
60
60
|
protected
|
61
61
|
|
62
62
|
def normalize_args
|
63
|
-
RequestParams.new(*@_args).with_default(default_params)
|
64
|
-
|
65
|
-
|
63
|
+
params = RequestParams.new(*@_args).with_default(default_params)
|
64
|
+
ConsoleUtils.logger.debug { params.to_a }
|
65
|
+
params
|
66
66
|
end
|
67
67
|
|
68
68
|
private
|
69
69
|
|
70
70
|
def show_complete_in!(reset = true)
|
71
71
|
return if @_time.nil?
|
72
|
-
|
72
|
+
if @_code && status_code = Rack::Utils::HTTP_STATUS_CODES[@_code]
|
73
|
+
print "=> ", pastel.public_send(status_color(@_code), "Completed ", pastel.bold("#{@_code} #{status_code}"), " in #{time_ms}"), "\n"
|
74
|
+
else
|
75
|
+
puts "=> #{pastel.green("Completed in #{time_ms}")}"
|
76
|
+
end
|
77
|
+
ensure
|
78
|
+
@_code = nil
|
73
79
|
@_time = nil
|
74
80
|
end
|
75
81
|
|
82
|
+
def pastel
|
83
|
+
ConsoleUtils.pastel
|
84
|
+
end
|
85
|
+
|
76
86
|
def show_transfered!(reset = true)
|
77
87
|
return if @_size.nil?
|
78
|
-
|
88
|
+
print "=> ", pastel.cyan("Transferred: #{size_downloaded}"), "\n"
|
89
|
+
ensure
|
79
90
|
@_size = nil
|
80
91
|
end
|
81
92
|
|
93
|
+
def status_color(code)
|
94
|
+
case code
|
95
|
+
when 200...400; :green
|
96
|
+
when 400...500; :red
|
97
|
+
when 500...600; :intense_red
|
98
|
+
else :yellow
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
82
102
|
private_constant :PBCOPY_MESSAGE,
|
83
|
-
:NO_RESPONSE,
|
103
|
+
:NO_RESPONSE,
|
84
104
|
:INFO_FORMAT
|
85
105
|
end
|
86
106
|
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.
|
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:
|
11
|
+
date: 2020-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,22 +16,22 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '7'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: pastel
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
@@ -149,6 +149,8 @@ files:
|
|
149
149
|
- console_utils.gemspec
|
150
150
|
- gemfiles/rails42.gemfile
|
151
151
|
- gemfiles/rails42.gemfile.lock
|
152
|
+
- gemfiles/rails5.gemfile
|
153
|
+
- gemfiles/rails5.gemfile.lock
|
152
154
|
- lib/awesome_print/proc_ext.rb
|
153
155
|
- lib/console_utils.rb
|
154
156
|
- lib/console_utils/active_record_utils.rb
|
@@ -191,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
193
|
- !ruby/object:Gem::Version
|
192
194
|
version: '0'
|
193
195
|
requirements: []
|
194
|
-
|
195
|
-
rubygems_version: 2.6.6
|
196
|
+
rubygems_version: 3.0.3
|
196
197
|
signing_key:
|
197
198
|
specification_version: 4
|
198
199
|
summary: Groovy tools for Rails Console.
|