Class: Nanoc::Core::IdentifiableCollection
- Inherits:
-
Object
- Object
- Nanoc::Core::IdentifiableCollection
show all
- Extended by:
- Forwardable
- Includes:
- Enumerable, ContractsSupport
- Defined in:
- lib/nanoc/core/identifiable_collection.rb
Instance Method Summary
collapse
enabled?, included, setup_once
Constructor Details
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
#[](arg) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 41
def [](arg)
if frozen?
get_memoized(arg)
else
get_unmemoized(arg)
end
end
|
#add(obj) ⇒ Object
69
70
71
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 69
def add(obj)
self.class.new(@config, @objects.add(obj))
end
|
#empty? ⇒ Boolean
64
65
66
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 64
def empty?
@objects.empty?
end
|
#find_all(arg) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 50
def find_all(arg)
if frozen?
find_all_memoized(arg)
else
find_all_unmemoized(arg)
end
end
|
#freeze ⇒ Object
33
34
35
36
37
38
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 33
def freeze
@objects.freeze
@objects.each(&:freeze)
build_mapping
super
end
|
#initialize_basic(config, objects = [], name = nil) ⇒ Object
21
22
23
24
25
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 21
def initialize_basic(config, objects = [], name = nil)
@config = config
@objects = Hamster::Vector.new(objects)
@name = name
end
|
#inspect ⇒ Object
28
29
30
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 28
def inspect
"<#{self.class}>"
end
|
#object_with_identifier(identifier) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 79
def object_with_identifier(identifier)
if frozen?
@mapping[identifier.to_s]
else
@objects.find { |i| i.identifier == identifier }
end
end
|
#reject(&block) ⇒ Object
74
75
76
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 74
def reject(&block)
self.class.new(@config, @objects.reject(&block))
end
|
#to_a ⇒ Object
59
60
61
|
# File 'lib/nanoc/core/identifiable_collection.rb', line 59
def to_a
@objects.to_a
end
|