Class: Leftovers::DefinitionToAdd

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, name: node.name, location: node.loc.name) ⇒ DefinitionToAdd

Returns a new instance of DefinitionToAdd.



7
8
9
10
11
# File 'lib/leftovers/definition_to_add.rb', line 7

def initialize(node, name: node.name, location: node.loc.name)
  @node = node
  @name = name
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

Instance Method Details

#keep?(file_collector) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/leftovers/definition_to_add.rb', line 17

def keep?(file_collector)
  @keep ||= file_collector.keep_line?(location.line) || ::Leftovers.config.keep === node
end

#privacy=(value) ⇒ Object



13
14
15
# File 'lib/leftovers/definition_to_add.rb', line 13

def privacy=(value)
  @node.privacy = value
end

#test?(file_collector) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/leftovers/definition_to_add.rb', line 21

def test?(file_collector)
  file_collector.test_line?(location.line) || ::Leftovers.config.test_only === node
end

#to_definition(file_collector) ⇒ Object



25
26
27
28
29
# File 'lib/leftovers/definition_to_add.rb', line 25

def to_definition(file_collector)
  return if keep?(file_collector)

  Definition.new(name, location: location, test: test?(file_collector))
end