Class: Nanoc::IdentifiableCollectionView
- Includes:
- Enumerable
- Defined in:
- lib/nanoc/base/views/identifiable_collection_view.rb
Direct Known Subclasses
ItemCollectionWithRepsView, ItemCollectionWithoutRepsView, LayoutCollectionView, MutableIdentifiableCollectionView, PostCompileItemCollectionView
Instance Method Summary collapse
-
#[](arg) ⇒ Object
-
#each {|object| ... } ⇒ self
Calls the given block once for each object, passing that object as a parameter.
-
#find_all(arg) ⇒ Enumerable
Finds all objects whose identifier matches the given argument.
-
#size ⇒ Integer
Methods inherited from View
Instance Method Details
#[](string) ⇒ nil, #identifier #[](regex) ⇒ nil, #identifier
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 86 def [](arg) prop_attribute = case arg when String, Nanoc::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 |
#each {|object| ... } ⇒ self
Calls the given block once for each object, passing that object as a parameter.
32 33 34 35 36 |
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 32 def each @context.dependency_tracker.bounce(unwrap, raw_content: true) @objects.each { |i| yield view_class.new(i, @context) } self end |
#find_all(arg) ⇒ Enumerable
Finds all objects whose identifier matches the given argument.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 49 def find_all(arg) prop_attribute = case arg when String, Nanoc::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 ⇒ Integer
39 40 41 42 |
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 39 def size @context.dependency_tracker.bounce(unwrap, raw_content: true) @objects.size end |