Class: Leftovers::Definition
- Inherits:
-
Object
- Object
- Leftovers::Definition
- Defined in:
- lib/leftovers/definition.rb
Instance Attribute Summary collapse
-
#location_s ⇒ Object
readonly
Returns the value of attribute location_s.
-
#name ⇒ Object
(also: #names)
readonly
Returns the value of attribute name.
-
#source_line ⇒ Object
readonly
Returns the value of attribute source_line.
-
#test ⇒ Object
(also: #test?)
readonly
Returns the value of attribute test.
Instance Method Summary collapse
- #highlighted_source(highlight = "\e[31m", normal = "\e[0m") ⇒ Object
- #in_collection?(collection) ⇒ Boolean
- #in_test_collection?(collection) ⇒ Boolean
-
#initialize(name, location: method_node.loc.expression, test: method_node.test_line? || ::Leftovers.config.test_only === method_node) ⇒ Definition
constructor
A new instance of Definition.
- #to_s ⇒ Object
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_s ⇒ Object (readonly)
Returns the value of attribute location_s.
5 6 7 |
# File 'lib/leftovers/definition.rb', line 5 def location_s @location_s end |
#name ⇒ Object (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_line ⇒ Object (readonly)
Returns the value of attribute source_line.
5 6 7 |
# File 'lib/leftovers/definition.rb', line 5 def source_line @source_line end |
#test ⇒ Object (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
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
41 42 43 |
# File 'lib/leftovers/definition.rb', line 41 def in_test_collection?(collection) collection.test_calls.include?(@name) end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/leftovers/definition.rb', line 27 def to_s @name.to_s end |