Class: Hologram::DocBlockCollection
- Inherits:
-
Object
- Object
- Hologram::DocBlockCollection
- Defined in:
- lib/hologram/doc_block_collection.rb
Instance Attribute Summary collapse
-
#doc_blocks ⇒ Object
Returns the value of attribute doc_blocks.
Instance Method Summary collapse
-
#add_doc_block(comment_block, file_name) ⇒ Object
this should throw an error if we have a match, but no yaml_match.
- #create_nested_structure ⇒ Object
-
#initialize ⇒ DocBlockCollection
constructor
A new instance of DocBlockCollection.
- #skip_block(doc_block, file_name) ⇒ Object
Constructor Details
#initialize ⇒ DocBlockCollection
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_blocks ⇒ Object
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 20 21 22 23 24 |
# 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 if @doc_blocks.has_key?(doc_block.name) DisplayMessage.warning("Multiple Hologram comments with name: #{doc_block.name}.") else @doc_blocks[doc_block.name] = doc_block end return doc_block end |
#create_nested_structure ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hologram/doc_block_collection.rb', line 26 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
52 53 54 |
# File 'lib/hologram/doc_block_collection.rb', line 52 def skip_block(doc_block, file_name) DisplayMessage.warning(doc_block.errors.join("\n") << " in #{file_name}. This hologram comment will be skipped.") end |