Class: Nanoc::Core::IdentifiableCollection

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

Direct Known Subclasses

ItemCollection, LayoutCollection

Instance Method Summary collapse

Constructor Details

#initializeIdentifiableCollection

Returns a new instance of IdentifiableCollection.



16
17
18
# File 'lib/nanoc/core/identifiable_collection.rb', line 16

def initialize
  raise 'IdentifiableCollection is abstract and cannot be instantiated'
end

Instance Method Details

#add(obj) ⇒ Object

contract C::RespondTo => self



60
61
62
# File 'lib/nanoc/core/identifiable_collection.rb', line 60

def add(obj)
  self.class.new(@config, @objects.add(obj))
end

#empty?Boolean

contract C::None => C::Bool

Returns:

  • (Boolean)


55
56
57
# File 'lib/nanoc/core/identifiable_collection.rb', line 55

def empty?
  @objects.empty?
end

#find_all(arg) ⇒ Object

contract C::Any => C::IterOf[C::RespondTo]



41
42
43
44
45
46
47
# File 'lib/nanoc/core/identifiable_collection.rb', line 41

def find_all(arg)
  if frozen?
    find_all_memoized(arg)
  else
    find_all_unmemoized(arg)
  end
end

#freezeObject

contract C::None => self



33
34
35
36
37
38
# File 'lib/nanoc/core/identifiable_collection.rb', line 33

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

#initialize_basic(config, objects = [], name = nil) ⇒ Object

contract C::Or[Hash, C::Named], C::IterOf[C::RespondTo], C::Maybe => C::Any



21
22
23
24
25
# File 'lib/nanoc/core/identifiable_collection.rb', line 21

def initialize_basic(config, objects = [], name = nil)
  @config = config
  @objects = Immutable::Vector.new(objects)
  @name = name
end

#inspectObject

contract C::None => String



28
29
30
# File 'lib/nanoc/core/identifiable_collection.rb', line 28

def inspect
  "<#{self.class}>"
end

#object_matching_glob(glob) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/nanoc/core/identifiable_collection.rb', line 77

def object_matching_glob(glob)
  if frozen?
    object_matching_glob_memoized(glob)
  else
    object_matching_glob_unmemoized(glob)
  end
end

#object_with_identifier(identifier) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/nanoc/core/identifiable_collection.rb', line 69

def object_with_identifier(identifier)
  if frozen?
    @mapping[identifier.to_s]
  else
    find { |i| i.identifier == identifier }
  end
end

#rejectObject

contract C::Func[C::RespondTo => C::Any] => self



65
66
67
# File 'lib/nanoc/core/identifiable_collection.rb', line 65

def reject(&)
  self.class.new(@config, @objects.reject(&))
end

#to_aObject

contract C::None => C::ArrayOf[C::RespondTo]



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

def to_a
  @objects.to_a
end