Class: Decode::Language::Ruby::Definition

Inherits:
Definition
  • Object
show all
Defined in:
lib/decode/language/ruby/definition.rb

Overview

A Ruby-specific definition.

Instance Attribute Summary collapse

Attributes inherited from Definition

#comments, #language, #name, #parent

Instance Method Summary collapse

Methods inherited from Definition

#container?, #convert, #documentation, #inspect, #long_form, #nested?, #path, #path_name, #qualified_form, #qualified_name, #short_form, #start_with?

Constructor Details

#initialize(node, *arguments, visibility: nil, **options) ⇒ Definition

Initialize the definition from the syntax tree node.



14
15
16
17
18
19
# File 'lib/decode/language/ruby/definition.rb', line 14

def initialize(node, *arguments, visibility: nil, **options)
	super(*arguments, **options)
	
	@node = node
	@visibility = visibility
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



26
27
28
# File 'lib/decode/language/ruby/definition.rb', line 26

def node
  @node
end

#The parser syntax tree node.(parsersyntaxtreenode.) ⇒ Object (readonly)



26
# File 'lib/decode/language/ruby/definition.rb', line 26

attr :node

#visibilityObject

Returns the value of attribute visibility.



29
30
31
# File 'lib/decode/language/ruby/definition.rb', line 29

def visibility
  @visibility
end

Instance Method Details

#locationObject



56
57
58
59
60
# File 'lib/decode/language/ruby/definition.rb', line 56

def location
	expression = @node.location.expression
	
	Location.new(expression.source_buffer.name, expression.line)
end

#multiline?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/decode/language/ruby/definition.rb', line 35

def multiline?
	@node.location.line != @node.location.last_line
end

#nested_nameObject



21
22
23
# File 'lib/decode/language/ruby/definition.rb', line 21

def nested_name
	"\##{@name}"
end

#public?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/decode/language/ruby/definition.rb', line 31

def public?
	@visibility == :public
end

#textObject

The source code associated with the definition.



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

def text
	expression = @node.location.expression
	lines = expression.source.lines
	if lines.count == 1
		return lines.first
	else
		if indentation = expression.source_line[/\A\s+/]
			# Remove all the indentation:
			lines.each{|line| line.sub!(indentation, '')}
		end
		
		return lines.join
	end
end

#The visibility of the definition.=(visibilityofthedefinition. = (value)) ⇒ Object



29
# File 'lib/decode/language/ruby/definition.rb', line 29

attr_accessor :visibility