Class: RSpecDocumentation::PageCollection
- Inherits:
-
Object
- Object
- RSpecDocumentation::PageCollection
- Includes:
- Paintbrush
- Defined in:
- lib/rspec_documentation/page_collection.rb
Overview
Builds content for a collection of page paths, collates failures from embedded examples. Writes the final structure to disk.
Instance Attribute Summary collapse
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#page_paths ⇒ Object
readonly
Returns the value of attribute page_paths.
Instance Method Summary collapse
- #documents ⇒ Object
- #examples_count ⇒ Object
- #flush ⇒ Object
- #generate ⇒ Object
-
#initialize(page_paths:) ⇒ PageCollection
constructor
A new instance of PageCollection.
Constructor Details
#initialize(page_paths:) ⇒ PageCollection
Returns a new instance of PageCollection.
11 12 13 14 15 |
# File 'lib/rspec_documentation/page_collection.rb', line 11 def initialize(page_paths:) @page_paths = page_paths.sort_by(&:to_s) @buffer = {} @failures = [] end |
Instance Attribute Details
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
7 8 9 |
# File 'lib/rspec_documentation/page_collection.rb', line 7 def failures @failures end |
#page_paths ⇒ Object (readonly)
Returns the value of attribute page_paths.
7 8 9 |
# File 'lib/rspec_documentation/page_collection.rb', line 7 def page_paths @page_paths end |
Instance Method Details
#documents ⇒ Object
25 26 27 28 29 |
# File 'lib/rspec_documentation/page_collection.rb', line 25 def documents @documents ||= page_paths.map do |path| Document.new(document: path.read, path: path, page_tree: page_tree(path: path)) end end |
#examples_count ⇒ Object
42 43 44 |
# File 'lib/rspec_documentation/page_collection.rb', line 42 def examples_count documents.map(&:specs).flatten.size end |
#flush ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rspec_documentation/page_collection.rb', line 31 def flush Util.bundle_dir.rmtree if Util.bundle_dir.directory? Util.bundle_dir.mkpath buffer.each do |path, content| path.dirname.mkpath Util.bundle_path(path).write(content) end write_index unless buffer.empty? end |
#generate ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rspec_documentation/page_collection.rb', line 17 def generate page_paths.zip(documents).each do |path, document| buffer[bundle_path_for(path)] = document.render failures.concat(document.failures) break if RSpecDocumentation.configuration.fail_fast && !failures.empty? end end |