Class: CallMap::Definition
- Inherits:
-
Object
- Object
- CallMap::Definition
- Defined in:
- lib/call_map/definition.rb
Overview
A single class / module / method definition.
This is a plain value object and must NOT depend on the parser (Prism). Building a Definition from an AST is the job of the parser boundary class, so that parser-specific code stays in one place.
Constant Summary collapse
- KINDS =
%i[class module instance_method class_method].freeze
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#lexical_nesting ⇒ Object
readonly
Returns the value of attribute lexical_nesting.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#superclass ⇒ Object
readonly
Returns the value of attribute superclass.
-
#visibility ⇒ Object
Writable so
private :foo-style post-declarations can adjust it.
Instance Method Summary collapse
- #class_or_module? ⇒ Boolean
-
#comments ⇒ Object
Leading comment lines attached at collection time ("#" stripped).
-
#initialize(kind:, name:, path:, line:, owner: nil, lexical_nesting: nil, superclass: nil, visibility: :public) ⇒ Definition
constructor
A new instance of Definition.
- #method? ⇒ Boolean
- #public_method? ⇒ Boolean
-
#qualified_name ⇒ Object
Human-readable qualified name used for lookups and tree output.
Constructor Details
#initialize(kind:, name:, path:, line:, owner: nil, lexical_nesting: nil, superclass: nil, visibility: :public) ⇒ Definition
Returns a new instance of Definition.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/call_map/definition.rb', line 20 def initialize(kind:, name:, path:, line:, owner: nil, lexical_nesting: nil, superclass: nil, visibility: :public) raise ArgumentError, "unknown kind: #{kind}" unless KINDS.include?(kind) @kind = kind @name = name @owner = owner @path = path @line = line @lexical_nesting = lexical_nesting @superclass = superclass @visibility = visibility # Free-form metadata; :comments holds the method's leading comment lines. @metadata = {} end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
35 36 37 |
# File 'lib/call_map/definition.rb', line 35 def kind @kind end |
#lexical_nesting ⇒ Object (readonly)
Returns the value of attribute lexical_nesting.
35 36 37 |
# File 'lib/call_map/definition.rb', line 35 def lexical_nesting @lexical_nesting end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
35 36 37 |
# File 'lib/call_map/definition.rb', line 35 def line @line end |
#metadata ⇒ Object
Returns the value of attribute metadata.
42 43 44 |
# File 'lib/call_map/definition.rb', line 42 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/call_map/definition.rb', line 35 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
35 36 37 |
# File 'lib/call_map/definition.rb', line 35 def owner @owner end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
35 36 37 |
# File 'lib/call_map/definition.rb', line 35 def path @path end |
#superclass ⇒ Object (readonly)
Returns the value of attribute superclass.
35 36 37 |
# File 'lib/call_map/definition.rb', line 35 def superclass @superclass end |
#visibility ⇒ Object
Writable so private :foo-style post-declarations can adjust it.
37 38 39 |
# File 'lib/call_map/definition.rb', line 37 def visibility @visibility end |
Instance Method Details
#class_or_module? ⇒ Boolean
49 50 51 |
# File 'lib/call_map/definition.rb', line 49 def class_or_module? %i[class module].include?(kind) end |
#comments ⇒ Object
Leading comment lines attached at collection time ("#" stripped).
45 46 47 |
# File 'lib/call_map/definition.rb', line 45 def comments [:comments] || [] end |
#method? ⇒ Boolean
53 54 55 |
# File 'lib/call_map/definition.rb', line 53 def method? %i[instance_method class_method].include?(kind) end |
#public_method? ⇒ Boolean
39 40 41 |
# File 'lib/call_map/definition.rb', line 39 def public_method? visibility == :public end |
#qualified_name ⇒ Object
Human-readable qualified name used for lookups and tree output.
- class / module: "Admin::ReportsController"
- instance method: "OrdersController#destroy"
- class method: "OrderDeleteService.execute"
62 63 64 65 66 67 68 |
# File 'lib/call_map/definition.rb', line 62 def qualified_name case kind when :instance_method then "#{owner}##{name}" when :class_method then "#{owner}.#{name}" else name end end |