Class: Jekyll::AgentAudit::BuildInventory
- Inherits:
-
Object
- Object
- Jekyll::AgentAudit::BuildInventory
- Defined in:
- lib/jekyll/agent_audit/build_inventory.rb
Instance Attribute Summary collapse
-
#collisions ⇒ Object
readonly
Returns the value of attribute collisions.
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #capture! ⇒ Object
- #complete? ⇒ Boolean
- #finalize! ⇒ Object
-
#initialize(site, configuration) ⇒ BuildInventory
constructor
A new instance of BuildInventory.
Constructor Details
#initialize(site, configuration) ⇒ BuildInventory
Returns a new instance of BuildInventory.
12 13 14 15 16 17 18 |
# File 'lib/jekyll/agent_audit/build_inventory.rb', line 12 def initialize(site, configuration) @site, @configuration = site, configuration @entries, @collisions, @diagnostics = [], [], [] @claims = Hash.new { |h, k| h[k] = [] } @captured = @complete = false @capture_failed = false end |
Instance Attribute Details
#collisions ⇒ Object (readonly)
Returns the value of attribute collisions.
10 11 12 |
# File 'lib/jekyll/agent_audit/build_inventory.rb', line 10 def collisions @collisions end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
10 11 12 |
# File 'lib/jekyll/agent_audit/build_inventory.rb', line 10 def diagnostics @diagnostics end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
10 11 12 |
# File 'lib/jekyll/agent_audit/build_inventory.rb', line 10 def entries @entries end |
Instance Method Details
#capture! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jekyll/agent_audit/build_inventory.rb', line 20 def capture! @captured = true each_owner do |owner| path = output_path(owner) add_claim(owner, path) if path end self rescue StandardError => e @capture_failed = true @diagnostics << {code: :inventory_capture_failed, message: e.} self end |
#complete? ⇒ Boolean
60 61 62 |
# File 'lib/jekyll/agent_audit/build_inventory.rb', line 60 def complete? @complete end |
#finalize! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jekyll/agent_audit/build_inventory.rb', line 33 def finalize! capture! unless @captured each_owner { |owner| add_claim(owner, output_path(owner)) if output_path(owner) } destination = File.(@site.dest.to_s) if Dir.exist?(destination) Dir.glob(File.join(destination, "**", "*")).sort.each do |absolute| next unless File.file?(absolute) relative = "/#{Pathname.new(absolute).relative_path_from(Pathname.new(destination)).to_s.tr('\\', '/')}" add_claim(nil, relative, final_artifact: true) unless @claims.key?(relative) end end @entries = @claims.values.flatten.uniq { |entry| [entry[:owner_token], entry[:output_path]] } @collisions = @claims.map do |path, owners| unique = owners.uniq { |entry| entry[:owner_token] } {output_path: path, primary: unique.first, owners: unique} if unique.length > 1 end.compact max = config_limit(:max_documents, 50_000) html_count = @entries.count { |entry| entry[:output_path].end_with?(".html") || entry[:route].to_s.end_with?("/") } if html_count > max @diagnostics << {code: :resource_limit, limit: :max_documents, value: html_count} @complete = false else @complete = !@capture_failed && @diagnostics.none? { |diagnostic| i[ownership_outside_destination inventory_capture_failed].include?(diagnostic[:code]) } end self end |