Class: Leftovers::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/leftovers/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, location: method_node.loc.expression, test: method_node.test_line? || ::Leftovers.config.test_only === method_node) ⇒ Definition

Returns a new instance of Definition.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/leftovers/definition.rb', line 10

def initialize(
  name,
  location: method_node.loc.expression,
  test: method_node.test_line? || ::Leftovers.config.test_only === method_node
)
  @name = name
  @path = location.source_buffer.name.to_s
  @source_line = location.source_line.to_s
  @location_column_range_begin = location.column_range.begin.to_i
  @location_column_range_end = location.column_range.end.to_i
  @location_source = location.source.to_s
  @location_s = location.to_s
  @test = test

  freeze
end

Instance Attribute Details

#location_sObject (readonly)

Returns the value of attribute location_s.



5
6
7
# File 'lib/leftovers/definition.rb', line 5

def location_s
  @location_s
end

#nameObject (readonly) Also known as: names

Returns the value of attribute name.



5
6
7
# File 'lib/leftovers/definition.rb', line 5

def name
  @name
end

#source_lineObject (readonly)

Returns the value of attribute source_line.



5
6
7
# File 'lib/leftovers/definition.rb', line 5

def source_line
  @source_line
end

#testObject (readonly) Also known as: test?

Returns the value of attribute test.



5
6
7
# File 'lib/leftovers/definition.rb', line 5

def test
  @test
end

Instance Method Details

#highlighted_source(highlight = "\e[31m", normal = "\e[0m") ⇒ Object



31
32
33
34
35
# File 'lib/leftovers/definition.rb', line 31

def highlighted_source(highlight = "\e[31m", normal = "\e[0m")
  @source_line[0...@location_column_range_begin].lstrip +
    highlight + @location_source + normal +
    @source_line[@location_column_range_end..-1].rstrip
end

#in_collection?(collection) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/leftovers/definition.rb', line 37

def in_collection?(collection)
  collection.calls.include?(@name) || (@test && in_test_collection?(collection))
end

#in_test_collection?(collection) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/leftovers/definition.rb', line 41

def in_test_collection?(collection)
  collection.test_calls.include?(@name)
end

#to_sObject



27
28
29
# File 'lib/leftovers/definition.rb', line 27

def to_s
  @name.to_s
end