Class: Hologram::DocBlockCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/hologram/doc_block_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocBlockCollection

Returns a new instance of DocBlockCollection.



5
6
7
# File 'lib/hologram/doc_block_collection.rb', line 5

def initialize
  @doc_blocks = {}
end

Instance Attribute Details

#doc_blocksObject

Returns the value of attribute doc_blocks.



3
4
5
# File 'lib/hologram/doc_block_collection.rb', line 3

def doc_blocks
  @doc_blocks
end

Instance Method Details

#add_doc_block(comment_block, file_name) ⇒ Object

this should throw an error if we have a match, but no yaml_match



10
11
12
13
14
15
16
17
18
19
# File 'lib/hologram/doc_block_collection.rb', line 10

def add_doc_block(comment_block, file_name)
  doc_block = DocumentBlock.from_comment(comment_block)
  return unless doc_block
  if !doc_block.is_valid?
    skip_block(doc_block, file_name)
    return
  end

  @doc_blocks[doc_block.name] = doc_block
end

#create_nested_structureObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hologram/doc_block_collection.rb', line 21

def create_nested_structure
  blocks_to_remove_from_top_level = []
  @doc_blocks.each do |key, doc_block|
    # don't do anything to top level doc_blocks
    next if !doc_block.parent

    parent = @doc_blocks[doc_block.parent]
    if parent.nil?
      DisplayMessage.warning("Hologram comment refers to parent: #{doc_block.parent}, but no other hologram comment has name: #{doc_block.parent}, skipping." )
    else
      parent.children[doc_block.name] = doc_block
      doc_block.parent = parent

      if doc_block.categories.empty?
        doc_block.categories = parent.categories
      end

      blocks_to_remove_from_top_level << doc_block.name
    end
  end

  blocks_to_remove_from_top_level.each do |key|
    @doc_blocks.delete(key)
  end
end

#skip_block(doc_block, file_name) ⇒ Object



47
48
49
# File 'lib/hologram/doc_block_collection.rb', line 47

def skip_block(doc_block, file_name)
  DisplayMessage.warning(doc_block.errors.join("\n") << " in #{file_name}. This hologram comment will be skipped.")
end