Class: Mutineer::Subject

Inherits:
Struct
  • Object
show all
Defined in:
lib/mutineer/subject.rb

Overview

One discoverable method and its AST node.

Location, namespace context, and the live Prism::DefNode are kept together because mutators walk the def node directly. namespace names the owner (module ::X inside Outer owns into X); lexical is the class/module chain as written (["Outer", "::X"]), which the redefine strategy needs to rebuild the same Module.nesting as a whole-file reload (#145).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#def_node ⇒ Object

Returns the value of attribute def_node

Returns:

  • (Object) —

    the current value of def_node



11
12
13
# File 'lib/mutineer/subject.rb', line 11

def def_node
  @def_node
end

#file ⇒ Object

Returns the value of attribute file

Returns:

  • (Object) —

    the current value of file



11
12
13
# File 'lib/mutineer/subject.rb', line 11

def file
  @file
end

#lexical ⇒ Object

Returns the value of attribute lexical

Returns:

  • (Object) —

    the current value of lexical



11
12
13
# File 'lib/mutineer/subject.rb', line 11

def lexical
  @lexical
end

#name ⇒ Object

Returns the value of attribute name

Returns:

  • (Object) —

    the current value of name



11
12
13
# File 'lib/mutineer/subject.rb', line 11

def name
  @name
end

#namespace ⇒ Object

Returns the value of attribute namespace

Returns:

  • (Object) —

    the current value of namespace



11
12
13
# File 'lib/mutineer/subject.rb', line 11

def namespace
  @namespace
end

#singleton ⇒ Object

Returns the value of attribute singleton

Returns:

  • (Object) —

    the current value of singleton



11
12
13
# File 'lib/mutineer/subject.rb', line 11

def singleton
  @singleton
end

Instance Method Details

#body_loc ⇒ Prism::Location?

Returns the body location for the subject, if any.

Returns:

  • (Prism::Location, nil) —

    body location or nil for empty methods.



30
31
32
# File 'lib/mutineer/subject.rb', line 30

def body_loc
  def_node.body&.location
end

#lexical_namespace ⇒ Array<String>

Class/module chain as written in the source, for textual wrappers. Falls back to namespace for subjects built without one.

Returns:

  • (Array<String>) —

    names; a root-anchored element keeps its ::.



23
24
25
# File 'lib/mutineer/subject.rb', line 23

def lexical_namespace
  lexical || namespace
end

#qualified_name ⇒ String

Returns the fully-qualified subject name.

Returns:

  • (String) —

    namespaced method name like Billing::Invoice#total.



15
16
17
# File 'lib/mutineer/subject.rb', line 15

def qualified_name
  namespace.join("::") + (singleton ? "." : "#") + name.to_s
end