Class: CallMap::MethodCall
- Inherits:
-
Object
- Object
- CallMap::MethodCall
- Defined in:
- lib/call_map/method_call.rb
Overview
A single method call extracted from a method body.
This is a plain value object and must NOT depend on the parser (Prism). Building a MethodCall from an AST is the job of CallExtractor.
Constant Summary collapse
- KNOWN_FRAMEWORK_METHODS =
Common Rails methods that appear as bare calls inside controllers and models. A bare call that stays unresolved and matches this list is displayed as a framework leaf.
%w[ redirect_to redirect_back render render_to_string head respond_to respond_with params request response session cookies flash logger helpers url_for current_user authenticate_user! sign_in sign_out authorize policy_scope raise puts pp ].freeze
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Instance Method Summary collapse
- #absolute? ⇒ Boolean
- #bare? ⇒ Boolean
- #callback? ⇒ Boolean
- #dynamic? ⇒ Boolean
-
#framework_leaf? ⇒ Boolean
Whether this call, IF it stays unresolved, should be shown as a framework leaf.
-
#initialize(receiver:, method_name:, line:, dynamic: false, absolute: false, callback: nil) ⇒ MethodCall
constructor
A new instance of MethodCall.
-
#label ⇒ Object
Human-readable label for tree output.
Constructor Details
#initialize(receiver:, method_name:, line:, dynamic: false, absolute: false, callback: nil) ⇒ MethodCall
Returns a new instance of MethodCall.
25 26 27 28 29 30 31 32 |
# File 'lib/call_map/method_call.rb', line 25 def initialize(receiver:, method_name:, line:, dynamic: false, absolute: false, callback: nil) @receiver = receiver @method_name = method_name @line = line @dynamic = dynamic @absolute = absolute @callback = callback end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
34 35 36 |
# File 'lib/call_map/method_call.rb', line 34 def callback @callback end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
34 35 36 |
# File 'lib/call_map/method_call.rb', line 34 def line @line end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
34 35 36 |
# File 'lib/call_map/method_call.rb', line 34 def method_name @method_name end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
34 35 36 |
# File 'lib/call_map/method_call.rb', line 34 def receiver @receiver end |
Instance Method Details
#absolute? ⇒ Boolean
40 41 42 |
# File 'lib/call_map/method_call.rb', line 40 def absolute? @absolute end |
#bare? ⇒ Boolean
48 49 50 |
# File 'lib/call_map/method_call.rb', line 48 def receiver.nil? end |
#callback? ⇒ Boolean
44 45 46 |
# File 'lib/call_map/method_call.rb', line 44 def callback? !@callback.nil? end |
#dynamic? ⇒ Boolean
36 37 38 |
# File 'lib/call_map/method_call.rb', line 36 def dynamic? @dynamic end |
#framework_leaf? ⇒ Boolean
Whether this call, IF it stays unresolved, should be shown as a
framework leaf. An explicit receiver that did not resolve points
outside the indexed app code; a bare call (including a callback filter
like Devise's before_action :authenticate_user!) is framework-ish
only when it matches the known Rails method list — an unlisted bare
call may just be an analysis miss, so it gets no suffix instead.
58 59 60 61 62 63 |
# File 'lib/call_map/method_call.rb', line 58 def framework_leaf? return false if dynamic? return KNOWN_FRAMEWORK_METHODS.include?(method_name) if true end |
#label ⇒ Object
Human-readable label for tree output.
66 67 68 69 70 71 72 |
# File 'lib/call_map/method_call.rb', line 66 def label base = receiver ? "#{receiver}.#{method_name}" : method_name return "#{callback} #{base}" if callback? return "#{base} [dynamic]" if dynamic? base end |