Class: Nanoc::Core::IdentifiableCollection
- Inherits:
-
Object
- Object
- Nanoc::Core::IdentifiableCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable, MemoWise
- Defined in:
- lib/nanoc/core/identifiable_collection.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#add(obj) ⇒ Object
contract C::RespondTo => self.
-
#empty? ⇒ Boolean
contract C::None => C::Bool.
-
#find_all(arg) ⇒ Object
contract C::Any => C::IterOf[C::RespondTo].
-
#freeze ⇒ Object
contract C::None => self.
-
#initialize ⇒ IdentifiableCollection
constructor
A new instance of IdentifiableCollection.
-
#initialize_basic(config, objects = [], name = nil) ⇒ Object
contract C::Or[Hash, C::Named], C::IterOf[C::RespondTo], C::Maybe => C::Any.
-
#inspect ⇒ Object
contract C::None => String.
- #object_matching_glob(glob) ⇒ Object
- #object_with_identifier(identifier) ⇒ Object
-
#reject ⇒ Object
contract C::Func[C::RespondTo => C::Any] => self.
-
#to_a ⇒ Object
contract C::None => C::ArrayOf[C::RespondTo].
Constructor Details
#initialize ⇒ IdentifiableCollection
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
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 |
#freeze ⇒ Object
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 |
#inspect ⇒ Object
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 |
#reject ⇒ Object
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_a ⇒ Object
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 |