console_utils 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/console_utils.rb +8 -24
- data/lib/console_utils/railtie.rb +8 -1
- data/lib/console_utils/repl_state.rb +82 -0
- data/lib/console_utils/request_utils/auth_automators.rb +2 -2
- data/lib/console_utils/request_utils/exap.rb +5 -7
- data/lib/console_utils/request_utils/request_params.rb +4 -2
- data/lib/console_utils/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e948128135cc22042b253c75da22a6d9bd9febaa
|
4
|
+
data.tar.gz: 53cd176f69e9bf1757831b07f514cf974755ae1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63a00ae0f1f4492c948caf7f5aa9336f425a5b9ad4a5027c87ac00ca568ad45190e8c2ae086d94c2b7aaf80da3b7ff23f055c3a86e584c9a418858c1c5d15fe5
|
7
|
+
data.tar.gz: cf73d753ad73eece8fc0bd3e8993f9ee6b65b9f87a85eca3663eb9cf0c593c1e5944a402c836e8d7ee09ed7e43e4fa11791248a4dde7d24ab0a90f965ab88db3
|
data/lib/console_utils.rb
CHANGED
@@ -50,7 +50,6 @@ module ConsoleUtils
|
|
50
50
|
|
51
51
|
MODULES = [
|
52
52
|
:ActiveRecordUtils,
|
53
|
-
:JSONOutput,
|
54
53
|
:RequestUtils,
|
55
54
|
:BenchUtils,
|
56
55
|
:OtherUtils
|
@@ -58,6 +57,9 @@ module ConsoleUtils
|
|
58
57
|
|
59
58
|
MODULES.each { |mod| autoload mod }
|
60
59
|
|
60
|
+
autoload :JSONOutput
|
61
|
+
autoload :ReplState
|
62
|
+
|
61
63
|
|
62
64
|
# :section: Configuration
|
63
65
|
|
@@ -151,7 +153,7 @@ module ConsoleUtils
|
|
151
153
|
|
152
154
|
def enabled_modules # :yields:
|
153
155
|
unless block_given?
|
154
|
-
return to_enum(__method__) { ConsoleUtils::MODULES.size - disabled_modules.
|
156
|
+
return to_enum(__method__) { ConsoleUtils::MODULES.size - disabled_modules.size }
|
155
157
|
end
|
156
158
|
|
157
159
|
(ConsoleUtils::MODULES - disabled_modules).each do |mod|
|
@@ -192,36 +194,18 @@ module ConsoleUtils
|
|
192
194
|
|
193
195
|
# Setup enabled modules for Pry context
|
194
196
|
def pry!
|
195
|
-
setup_modules_to
|
197
|
+
setup_modules_to(TOPLEVEL_BINDING.eval('self'))
|
196
198
|
end
|
197
199
|
|
198
200
|
# Setup enabled modules by extending given context
|
199
|
-
def setup_modules_to
|
200
|
-
|
201
|
-
|
202
|
-
logger.tagged(name) do
|
203
|
-
unless block_given?
|
204
|
-
logger.warn { "Trying to setup with empty context" }
|
205
|
-
return
|
206
|
-
end
|
207
|
-
|
208
|
-
if ENV["CONSOLE_UTILS_DEBUG"] == "1"
|
209
|
-
logger.level = Logger::DEBUG
|
210
|
-
logger.debug { "Console instance: #{yield().inspect}" }
|
211
|
-
end
|
212
|
-
|
213
|
-
enabled_modules do |mod|
|
214
|
-
logger.debug { "extending with #{mod.inspect}" }
|
215
|
-
yield().extend(mod)
|
216
|
-
end
|
217
|
-
end
|
201
|
+
def setup_modules_to(context = nil)
|
202
|
+
ReplState.setup(context)
|
218
203
|
end
|
219
|
-
|
220
204
|
end
|
221
205
|
|
222
206
|
ActiveSupport.run_load_hooks(:console_utils, self)
|
223
207
|
end
|
224
208
|
|
225
|
-
if defined?
|
209
|
+
if defined? Rails
|
226
210
|
require "console_utils/railtie"
|
227
211
|
end
|
@@ -10,7 +10,14 @@ module ConsoleUtils
|
|
10
10
|
options = app.config.console_utils
|
11
11
|
|
12
12
|
options.disabled_modules ||= ConsoleUtils.disabled_modules
|
13
|
-
|
13
|
+
|
14
|
+
if !defined?(ActiveRecord) || !ConsoleUtils.disabled_modules.include?(:ActiveRecordUtils)
|
15
|
+
options.disabled_modules << :ActiveRecordUtils
|
16
|
+
|
17
|
+
ActiveSupport.on_load(:active_record) do
|
18
|
+
ConsoleUtils.disabled_modules.delete(:ActiveRecordUtils)
|
19
|
+
end
|
20
|
+
end
|
14
21
|
|
15
22
|
ActiveSupport.on_load(:console_utils) do
|
16
23
|
options.each { |k, v| public_send(:"#{k}=", v) }
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module ConsoleUtils
|
2
|
+
class ReplState
|
3
|
+
IVAR = :"@__console_utils__"
|
4
|
+
EMPTY_CONTEXT_ALERT = "Trying to setup with empty context".freeze
|
5
|
+
ALREADY_EXTENDED_ALERT = "Trying to setup again on fully extended context".freeze
|
6
|
+
CONTEXT_DEBUG_MSG = "Console instance: %p".freeze
|
7
|
+
MODULE_EXTENDS_MSG = "extending context...".freeze
|
8
|
+
|
9
|
+
def self.setup(context)
|
10
|
+
state = context.instance_variable_get(IVAR) || ReplState.new
|
11
|
+
|
12
|
+
return true if state.frozen?
|
13
|
+
|
14
|
+
logger.tagged("console_utils-#{VERSION}") do
|
15
|
+
if context.nil?
|
16
|
+
logger.warn { EMPTY_CONTEXT_ALERT }
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
unless state.persisted?
|
21
|
+
logger.level = Logger::WARN
|
22
|
+
|
23
|
+
if ENV["CONSOLE_UTILS_DEBUG"]
|
24
|
+
logger.level = Logger::DEBUG
|
25
|
+
logger.debug { CONTEXT_DEBUG_MSG % context }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if state.fully_extended?
|
30
|
+
logger.warn { ALREADY_EXTENDED_ALERT }
|
31
|
+
else
|
32
|
+
ConsoleUtils.enabled_modules do |mod|
|
33
|
+
state.extending(mod.to_s) do
|
34
|
+
logger.debug { MODULE_EXTENDS_MSG }
|
35
|
+
context.extend(mod)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context.instance_variable_set(IVAR, state.persist!)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.logger
|
45
|
+
ConsoleUtils.logger
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
@version = VERSION
|
50
|
+
@extensions = []
|
51
|
+
@persisted = false
|
52
|
+
end
|
53
|
+
|
54
|
+
def persisted?
|
55
|
+
@persisted
|
56
|
+
end
|
57
|
+
|
58
|
+
def persist!
|
59
|
+
@persisted = true
|
60
|
+
fully_extended? ? freeze : self
|
61
|
+
end
|
62
|
+
|
63
|
+
def fully_extended?
|
64
|
+
@persisted && @extensions.size == ConsoleUtils.enabled_modules.size
|
65
|
+
end
|
66
|
+
|
67
|
+
def extending(mod_name)
|
68
|
+
if include?(mod_name)
|
69
|
+
true
|
70
|
+
else
|
71
|
+
ConsoleUtils.logger.tagged(mod_name) { yield }
|
72
|
+
@extensions << mod_name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def include?(mod)
|
77
|
+
@extensions.include?(mod.to_s)
|
78
|
+
end
|
79
|
+
|
80
|
+
alias_method :extended_with?, :include?
|
81
|
+
end
|
82
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module ConsoleUtils::RequestUtils
|
2
2
|
class DefaultAuthAutomator
|
3
3
|
def self.call(rq)
|
4
|
+
p rq
|
4
5
|
if rq.can_auto_auth?
|
5
|
-
rq.params[ConsoleUtils.token_param] ||=
|
6
|
-
ConsoleUtils.default_token.presence or ConsoleUtils.auto_token_for(rq.uid)
|
6
|
+
rq.params[ConsoleUtils.token_param] ||= ConsoleUtils.default_token.presence || ConsoleUtils.auto_token_for(rq.uid)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -5,7 +5,11 @@ module ConsoleUtils::RequestUtils #:nodoc:
|
|
5
5
|
INSPECT_FORMAT = "<Local: %s (%s)>".freeze
|
6
6
|
|
7
7
|
ConsoleUtils.request_methods.each do |reqm|
|
8
|
-
define_method(reqm)
|
8
|
+
define_method(reqm) do |*args|
|
9
|
+
@url, *@_args = args
|
10
|
+
app.public_send(reqm, @url, *normalize_args)
|
11
|
+
self
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
def to_s
|
@@ -29,11 +33,5 @@ module ConsoleUtils::RequestUtils #:nodoc:
|
|
29
33
|
def response_body
|
30
34
|
app.controller.try(:response_body) || response.try(:body)
|
31
35
|
end
|
32
|
-
|
33
|
-
def resp_wrap(meth, url, *args)
|
34
|
-
@url, @_args = url, args
|
35
|
-
app.send(meth, url, *normalize_args)
|
36
|
-
self
|
37
|
-
end
|
38
36
|
end
|
39
37
|
end
|
@@ -3,12 +3,14 @@ module ConsoleUtils::RequestUtils
|
|
3
3
|
attr_accessor :uid
|
4
4
|
|
5
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
|
+
|
6
8
|
if uid_or_params.is_a? Hash
|
7
9
|
headers, params, uid_or_params = [params, uid_or_params, nil]
|
8
10
|
end
|
9
11
|
|
10
|
-
@params
|
11
|
-
@headers = headers
|
12
|
+
@params = params if params
|
13
|
+
@headers = headers if headers
|
12
14
|
@uid = auto_auth? && ((uid_or_params.nil? || uid_or_params == true) ? ConsoleUtils.default_uid : uid_or_params)
|
13
15
|
|
14
16
|
ConsoleUtils.logger.debug { "#{uid}, #{params()}, #{headers()}" }
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- lib/console_utils/other_utils.rb
|
165
165
|
- lib/console_utils/pry.rb
|
166
166
|
- lib/console_utils/railtie.rb
|
167
|
+
- lib/console_utils/repl_state.rb
|
167
168
|
- lib/console_utils/request_utils.rb
|
168
169
|
- lib/console_utils/request_utils/auth_automators.rb
|
169
170
|
- lib/console_utils/request_utils/exap.rb
|