Class: Nanoc::Int::IdentifiableCollection Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, ContractsSupport
Defined in:
lib/nanoc/base/entities/identifiable_collection.rb

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

Instance Method Summary collapse

Methods included from ContractsSupport

included

Constructor Details

#initialize(config) ⇒ IdentifiableCollection

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.

Returns a new instance of IdentifiableCollection.



16
17
18
19
20
# File 'lib/nanoc/base/entities/identifiable_collection.rb', line 16

def initialize(config)
  @config = config

  @objects = []
end

Instance Method Details

#[](arg) ⇒ 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.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nanoc/base/entities/identifiable_collection.rb', line 31

def [](arg)
  case arg
  when Nanoc::Identifier
    object_with_identifier(arg)
  when String
    object_with_identifier(arg) || object_matching_glob(arg)
  when Regexp
    @objects.find { |i| i.identifier.to_s =~ arg }
  else
    raise ArgumentError, "don’t know how to fetch objects by #{arg.inspect}"
  end
end

#delete_if(&block) ⇒ 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.



55
56
57
58
# File 'lib/nanoc/base/entities/identifiable_collection.rb', line 55

def delete_if(&block)
  @objects.delete_if(&block)
  self
end

#empty?Boolean

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.

Returns:

  • (Boolean)


50
51
52
# File 'lib/nanoc/base/entities/identifiable_collection.rb', line 50

def empty?
  @objects.empty?
end

#freezeObject

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.



23
24
25
26
27
28
# File 'lib/nanoc/base/entities/identifiable_collection.rb', line 23

def freeze
  @objects.freeze
  @objects.each(&:freeze)
  build_mapping
  super
end

#to_aObject

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.



45
46
47
# File 'lib/nanoc/base/entities/identifiable_collection.rb', line 45

def to_a
  @objects
end