Class: Leftovers::DefinitionCollection

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

Instance Method Summary collapse

Constructor Details

#initializeDefinitionCollection

Returns a new instance of DefinitionCollection.



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

def initialize
  @definitions_to_add = {}
  @definition_sets_to_add = []
end

Instance Method Details

#add(node, name: node.name, loc: node.loc.name) ⇒ Object



14
15
16
# File 'lib/leftovers/definition_collection.rb', line 14

def add(node, name: node.name, loc: node.loc.name)
  @definitions_to_add[name] = DefinitionToAdd.new(node, name: name, location: loc)
end

#add_definition_node(definition_node) ⇒ Object



10
11
12
# File 'lib/leftovers/definition_collection.rb', line 10

def add_definition_node(definition_node)
  add(definition_node, loc: definition_node.loc)
end

#add_definition_set(definition_node_set) ⇒ Object



18
19
20
21
22
# File 'lib/leftovers/definition_collection.rb', line 18

def add_definition_set(definition_node_set)
  @definition_sets_to_add << definition_node_set.definitions.map do |definition_node|
    DefinitionToAdd.new(definition_node, location: definition_node.loc)
  end
end

#set_privacy(name, to) ⇒ Object



24
25
26
# File 'lib/leftovers/definition_collection.rb', line 24

def set_privacy(name, to)
  @definitions_to_add[name]&.privacy = to
end

#to_definitions(file_collector) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/leftovers/definition_collection.rb', line 28

def to_definitions(file_collector)
  @definitions_to_add.each_value.map { |d| d.to_definition(file_collector) } +
    @definition_sets_to_add.map do |definition_set|
      next if definition_set.any? { |d| d.keep?(file_collector) }

      DefinitionSet.new(definition_set.map { |d| d.to_definition(file_collector) })
    end
end