Class: Decode::Language::Ruby::Call

Inherits:
Definition show all
Defined in:
lib/decode/language/ruby/call.rb

Overview

A Ruby-specific block which might carry other definitions.

Instance Attribute Summary

Attributes inherited from Definition

#The comment lines which directly preceeded the definition., #The language the symbol is defined within., #The path to the definition, relative to the parent., #The source file containing this definition., #comments, #language, #parent, #path, #source, #visibility

Instance Method Summary collapse

Methods inherited from Definition

#:public, :private, :protected=, #The parent definition, defining lexical scope.=, #The symbol name e.g. `:Decode`.=, #convert, #coverage_relevant?, #documentation, #documented?, #full_path, #initialize, #inspect, #location, #multiline?, #name, #nested?, #nested_name, #public?, #qualified_name, #start_with?, #text

Constructor Details

This class inherits a constructor from Decode::Definition

Instance Method Details

#container?Boolean

A block can sometimes be a container for other definitions.

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/decode/language/ruby/call.rb', line 14

def container?
  case block = @node&.block
  when nil
    false
  when Prism::BlockArgumentNode
    false
  when Prism::BlockNode
    # Technically, all block nodes are containers, but we prefer to be opinionated about when we consider them containers:
    block.opening == "do"
  else
    false
  end
end

#long_formObject

The long form of the class. e.g. ‘foo(:bar)`.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/decode/language/ruby/call.rb', line 40

def long_form
  if @node.location.start_line == @node.location.end_line
    @node.location.slice
  else
    # For multiline calls, use the actual call name with arguments
    if @node.arguments && @node.arguments.arguments.any?
      argument_text = @node.arguments.arguments.map{|argument| argument.location.slice}.join(", ")
      "#{@node.name}(#{argument_text})"
    else
      @node.name.to_s
    end
  end
end

#qualified_formObject

The fully qualified name of the block. e.g. ‘class ::Barnyard::Dog`.



56
57
58
# File 'lib/decode/language/ruby/call.rb', line 56

def qualified_form
  self.qualified_name
end

#short_formObject

The short form of the class. e.g. ‘foo`.



30
31
32
33
34
35
36
# File 'lib/decode/language/ruby/call.rb', line 30

def short_form
  if @node&.block && @node.block.opening == "{"
    "#{name} { ... }"
  else
    name.to_s
  end
end