class Nanoc::Core::IdentifiableCollectionView

Constants

NOTHING

Public Class Methods

new(objects, context) click to toggle source

@api private

Calls superclass method Nanoc::Core::View::new
# File lib/nanoc/core/identifiable_collection_view.rb, line 11
def initialize(objects, context)
  super(context)
  @objects = objects
end

Public Instance Methods

[](arg) click to toggle source

@overload [](string)

Finds the object whose identifier matches the given string.

If the glob syntax is enabled, the string can be a glob, in which case
this method finds the first object that matches the given glob.

@param [String] string

@return [nil] if no object matches the string

@return [#identifier] if an object was found

@overload [](regex)

Finds the object whose identifier matches the given regular expression.

@param [Regex] regex

@return [nil] if no object matches the regex

@return [#identifier] if an object was found
# File lib/nanoc/core/identifiable_collection_view.rb, line 94
def [](arg)
  prop_attribute =
    case arg
    when String, Nanoc::Core::Identifier
      [arg.to_s]
    when Regexp
      [arg]
    else
      true
    end

  @context.dependency_tracker.bounce(_unwrap, raw_content: prop_attribute)
  res = @objects[arg]
  res && view_class.new(res, @context)
end
_unwrap() click to toggle source

@api private

# File lib/nanoc/core/identifiable_collection_view.rb, line 17
def _unwrap
  @objects
end
each() { |view_class| ... } click to toggle source

Calls the given block once for each object, passing that object as a parameter.

@yieldparam [#identifier] object

@yieldreturn [void]

@return [self]

# File lib/nanoc/core/identifiable_collection_view.rb, line 35
def each
  @context.dependency_tracker.bounce(_unwrap, raw_content: true)
  @objects.each { |i| yield view_class.new(i, @context) }
  self
end
find_all(arg = NOTHING, &block) click to toggle source

Finds all objects whose identifier matches the given argument.

@param [String, Regex] arg

@return [Enumerable]

# File lib/nanoc/core/identifiable_collection_view.rb, line 52
def find_all(arg = NOTHING, &block)
  if NOTHING.equal?(arg)
    @context.dependency_tracker.bounce(_unwrap, raw_content: true)
    return @objects.map { |i| view_class.new(i, @context) }.select(&block)
  end

  prop_attribute =
    case arg
    when String, Nanoc::Core::Identifier
      [arg.to_s]
    when Regexp
      [arg]
    else
      true
    end

  @context.dependency_tracker.bounce(_unwrap, raw_content: prop_attribute)
  @objects.find_all(arg).map { |i| view_class.new(i, @context) }
end
size() click to toggle source

@return [Integer]

# File lib/nanoc/core/identifiable_collection_view.rb, line 42
def size
  @context.dependency_tracker.bounce(_unwrap, raw_content: true)
  @objects.size
end
view_class() click to toggle source

@abstract

@api private

# File lib/nanoc/core/identifiable_collection_view.rb, line 24
def view_class
  raise NotImplementedError
end