Class: SidekiqAdhocJob::Utils::ClassInspector
- Inherits:
-
Object
- Object
- SidekiqAdhocJob::Utils::ClassInspector
- Defined in:
- lib/sidekiq_adhoc_job/utils/class_inspector.rb
Instance Attribute Summary collapse
-
#klass_name ⇒ Object
readonly
Returns the value of attribute klass_name.
-
#klass_obj ⇒ Object
readonly
Returns the value of attribute klass_obj.
-
#method_parameters ⇒ Object
readonly
Returns the value of attribute method_parameters.
Instance Method Summary collapse
- #has_rest_parameter?(method_name) ⇒ Boolean
-
#initialize(klass_name) ⇒ ClassInspector
constructor
A new instance of ClassInspector.
- #klass_method(method) ⇒ Object
- #optional_kw_parameters(method_name) ⇒ Object
- #optional_parameters(method_name) ⇒ Object
- #parameters(method_name) ⇒ Object
- #required_kw_parameters(method_name) ⇒ Object
- #required_parameters(method_name) ⇒ Object
Constructor Details
#initialize(klass_name) ⇒ ClassInspector
Returns a new instance of ClassInspector.
7 8 9 10 11 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 7 def initialize(klass_name) @klass_name = klass_name @klass_obj = klass_name.new @method_parameters = {} end |
Instance Attribute Details
#klass_name ⇒ Object (readonly)
Returns the value of attribute klass_name.
5 6 7 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 5 def klass_name @klass_name end |
#klass_obj ⇒ Object (readonly)
Returns the value of attribute klass_obj.
5 6 7 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 5 def klass_obj @klass_obj end |
#method_parameters ⇒ Object (readonly)
Returns the value of attribute method_parameters.
5 6 7 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 5 def method_parameters @method_parameters end |
Instance Method Details
#has_rest_parameter?(method_name) ⇒ Boolean
46 47 48 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 46 def has_rest_parameter?(method_name) !!parameters(method_name)[:rest] end |
#klass_method(method) ⇒ Object
50 51 52 53 54 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 50 def klass_method(method) return method if method.owner == klass_name klass_method(method.super_method) end |
#optional_kw_parameters(method_name) ⇒ Object
42 43 44 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 42 def optional_kw_parameters(method_name) parameters(method_name)[:key] || [] end |
#optional_parameters(method_name) ⇒ Object
34 35 36 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 34 def optional_parameters(method_name) parameters(method_name)[:opt] || [] end |
#parameters(method_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 13 def parameters(method_name) return method_parameters[method_name] if method_parameters[method_name] klass_method = klass_method(klass_obj.method(method_name)) params = klass_method .parameters .group_by { |type, _| type } .inject({}) do |acc, (type, params)| acc[type] = params.map(&:last) acc end method_parameters[method_name] = params params end |
#required_kw_parameters(method_name) ⇒ Object
38 39 40 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 38 def required_kw_parameters(method_name) parameters(method_name)[:keyreq] || [] end |
#required_parameters(method_name) ⇒ Object
30 31 32 |
# File 'lib/sidekiq_adhoc_job/utils/class_inspector.rb', line 30 def required_parameters(method_name) parameters(method_name)[:req] || [] end |