Module: Nanoc::Helpers::Breadcrumbs::Int Private

Defined in:
lib/nanoc/helpers/breadcrumbs.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Constant Summary collapse

DEFAULT_TIEBREAKER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

lambda do |items, pattern|
  identifiers = items.map(&:identifier).sort
  $stderr.puts <<~WARNING
    Warning: The breadcrumbs trail (generated by #breadcrumbs_trail) found more than one potential parent item at #{pattern} (found #{identifiers.join(', ')}). Nanoc will pick the first item as the parent. Consider eliminating the ambiguity by making only one item match #{pattern}, or by passing a `:tiebreaker` option to `#breadcrumbs_trail`. (This situation will be an error in the next major version of Nanoc.)
  WARNING

  items.min_by(&:identifier)
end
ERROR_TIEBREAKER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

lambda do |items, pattern|
  raise AmbiguousAncestorError.new(pattern, items)
end

Class Method Summary collapse

Class Method Details

.find_one(items, pat, tiebreaker) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nanoc/helpers/breadcrumbs.rb', line 59

def self.find_one(items, pat, tiebreaker)
  res = items.find_all(pat)
  case res.size
  when 0
    nil
  when 1
    res.first
  else
    if tiebreaker.arity == 1
      tiebreaker.call(res)
    else
      tiebreaker.call(res, pat)
    end
  end
end

.patterns_for_prefix(prefix) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

e.g. patterns_for_prefix(‘/foo/1.0’)

> [‘/foo/1.0.*’, ‘/foo/1.*’]



49
50
51
52
53
54
55
56
57
# File 'lib/nanoc/helpers/breadcrumbs.rb', line 49

def self.patterns_for_prefix(prefix)
  prefixes =
    unfold(prefix) do |old_prefix|
      new_prefix = Nanoc::Core::Identifier.new(old_prefix).without_ext
      new_prefix == old_prefix ? nil : new_prefix
    end

  prefixes.map { |pr| pr + '.*' }
end

.unfold(obj) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

e.g. unfold(10.class, &:superclass)

> [Integer, Numeric, Object, BasicObject]



36
37
38
39
40
41
42
43
44
45
# File 'lib/nanoc/helpers/breadcrumbs.rb', line 36

def self.unfold(obj, &)
  acc = [obj]

  res = yield(obj)
  if res
    acc + unfold(res, &)
  else
    acc
  end
end