Class: Nanoc::Core::BasicItemRepCollectionView
- Includes:
- Enumerable
- Defined in:
- lib/nanoc/core/views/basic_item_rep_collection_view.rb
Direct Known Subclasses
CompilationItemRepCollectionView, PostCompileItemRepCollectionView
Defined Under Namespace
Classes: NoSuchItemRepError
Instance Method Summary collapse
-
#[](rep_name) ⇒ nil, Nanoc::Core::BasicItemRepView
Return the item rep with the given name, or nil if no item rep exists.
- #_unwrap ⇒ Object private
-
#each {|item| ... } ⇒ self
Calls the given block once for each item rep, passing that item rep as a parameter.
-
#fetch(rep_name) ⇒ Nanoc::Core::BasicItemRepView
Return the item rep with the given name, or raises an exception if there is no rep with the given name.
-
#initialize(item_reps, context) ⇒ BasicItemRepCollectionView
constructor
private
A new instance of BasicItemRepCollectionView.
- #size ⇒ Integer
- #to_ary ⇒ Object
- #view_class ⇒ Object private
Methods inherited from View
Methods included from ContractsSupport
enabled?, included, setup_once, warn_about_performance
Constructor Details
#initialize(item_reps, context) ⇒ BasicItemRepCollectionView
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 BasicItemRepCollectionView.
15 16 17 18 |
# File 'lib/nanoc/core/views/basic_item_rep_collection_view.rb', line 15 def initialize(item_reps, context) super(context) @item_reps = item_reps end |
Instance Method Details
#[](rep_name) ⇒ nil, Nanoc::Core::BasicItemRepView
Return the item rep with the given name, or nil if no item rep exists.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nanoc/core/views/basic_item_rep_collection_view.rb', line 60 def [](rep_name) case rep_name when Symbol res = @item_reps.find { |ir| ir.name == rep_name } res && view_class.new(res, @context) when Integer raise ArgumentError, 'expected BasicItemRepCollectionView#[] to be called with a ' \ 'symbol (you likely want `.reps[:default]` rather than ' \ "`.reps[#{rep_name}]`)" else raise ArgumentError, 'expected BasicItemRepCollectionView#[] to be called with a ' \ 'symbol' end end |
#_unwrap ⇒ 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.
21 22 23 |
# File 'lib/nanoc/core/views/basic_item_rep_collection_view.rb', line 21 def _unwrap @item_reps end |
#each {|item| ... } ⇒ self
Calls the given block once for each item rep, passing that item rep as a parameter.
42 43 44 45 |
# File 'lib/nanoc/core/views/basic_item_rep_collection_view.rb', line 42 def each @item_reps.each { |ir| yield view_class.new(ir, @context) } self end |
#fetch(rep_name) ⇒ Nanoc::Core::BasicItemRepView
Return the item rep with the given name, or raises an exception if there is no rep with the given name.
85 86 87 88 89 90 91 92 |
# File 'lib/nanoc/core/views/basic_item_rep_collection_view.rb', line 85 def fetch(rep_name) res = @item_reps.find { |ir| ir.name == rep_name } if res view_class.new(res, @context) else raise NoSuchItemRepError.new(rep_name) end end |
#size ⇒ Integer
48 49 50 |
# File 'lib/nanoc/core/views/basic_item_rep_collection_view.rb', line 48 def size @item_reps.size end |
#to_ary ⇒ Object
30 31 32 |
# File 'lib/nanoc/core/views/basic_item_rep_collection_view.rb', line 30 def to_ary @item_reps.map { |ir| view_class.new(ir, @context) } end |
#view_class ⇒ 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.
26 27 28 |
# File 'lib/nanoc/core/views/basic_item_rep_collection_view.rb', line 26 def view_class Nanoc::Core::BasicItemRepView end |