Module: Railjet::Console::RailjetHelpers
- Defined in:
- lib/railjet/console/debug_helpers.rb
Overview
Adds helper methods for auditing of console customer usage
Defined Under Namespace
Classes: RailjetContextHelper
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.load ⇒ Object
98
99
100
|
# File 'lib/railjet/console/debug_helpers.rb', line 98
def self.load
Object.include(self)
end
|
Instance Method Details
#console_context ⇒ Object
39
40
41
42
43
|
# File 'lib/railjet/console/debug_helpers.rb', line 39
def console_context
@context_class.init(
*context_params
)
end
|
#find_context_param(type, method_name) ⇒ Object
80
81
82
|
# File 'lib/railjet/console/debug_helpers.rb', line 80
def find_context_param(type, method_name)
send("find_#{type}_context_param", method_name)
end
|
#find_context_params ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/railjet/console/debug_helpers.rb', line 61
def find_context_params
parameters = []
missing_methods = []
@context_class.method(:init).parameters.each do |param|
param_value, missing_method_error = find_context_param(
param[0], param[1]
)
parameters.push(param_value)
if missing_method_error.present?
missing_methods.push(missing_method_error)
end
end
[parameters, missing_methods]
end
|
#find_keyreq_context_param(method_name) ⇒ Object
Also known as:
find_key_context_param
91
92
93
94
95
|
# File 'lib/railjet/console/debug_helpers.rb', line 91
def find_keyreq_context_param(method_name)
[{ method_name => send(method_name) }, nil]
rescue StandardError => e
[{ method_name => nil }, { method_name => e.message }]
end
|
#find_req_context_param(method_name) ⇒ Object
Also known as:
find_opt_context_param
84
85
86
87
88
|
# File 'lib/railjet/console/debug_helpers.rb', line 84
def find_req_context_param(method_name)
[send(method_name), nil]
rescue StandardError => e
[nil, { method_name => e.message }]
end
|
49
50
51
|
# File 'lib/railjet/console/debug_helpers.rb', line 49
def form(klass, clean_params)
klass.new(clean_params).tap(&:validate)
end
|
#railjet_helper_after_init_message ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/railjet/console/debug_helpers.rb', line 15
def railjet_helper_after_init_message
puts 'Setup finished. railjet helpers are now available from console'
puts 'available commands:'
puts "\t- use_case(<Class>)"
puts "\t- form(<Class>, params)"
puts "\t- console_context"
end
|
#railjet_helper_after_load_message ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/railjet/console/debug_helpers.rb', line 23
def railjet_helper_after_load_message
puts '*' * 61
puts "\nCall 'setup_railjet' to setup and debug Railjet"
puts 'Argument are:'
method(:setup_railjet).parameters.each do |param|
case param[0]
when :key, :keyreq
puts "\t- #{param[1]}:"
else
puts "\t- #{param[1]}"
end
end
puts "\n"
puts '*' * 61
end
|
#setup_railjet(context_class: nil) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/railjet/console/debug_helpers.rb', line 7
def setup_railjet(context_class: nil)
@context_class = context_class
@context_class ||= RailjetContextHelper.determine_context_class
railjet_helper_after_init_message
end
|
#use_case(klass) ⇒ Object
45
46
47
|
# File 'lib/railjet/console/debug_helpers.rb', line 45
def use_case(klass)
klass.new(console_context)
end
|