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
61 62 63 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 61 def add(obj) self.class.new(@config, @objects.add(obj)) end |
#empty? ⇒ Boolean
contract C::None => C::Bool
56 57 58 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 56 def empty? @objects.empty? end |
#find_all(arg) ⇒ Object
contract C::Any => C::IterOf[C::RespondTo]
42 43 44 45 46 47 48 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 42 def find_all(arg) if frozen? find_all_memoized(arg) else find_all_unmemoized(arg) end end |
#freeze ⇒ Object
contract C::None => self
34 35 36 37 38 39 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 34 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[:identifier]], C::Maybe[String] => C::Any
22 23 24 25 26 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 22 def initialize_basic(config, objects = [], name = nil) @config = config @objects = Immutable::Vector.new(objects) @name = name end |
#inspect ⇒ Object
contract C::None => String
29 30 31 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 29 def inspect "<#{self.class}>" end |
#object_matching_glob(glob) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 78 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
70 71 72 73 74 75 76 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 70 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
66 67 68 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 66 def reject(&) self.class.new(@config, @objects.reject(&)) end |
#to_a ⇒ Object
contract C::None => C::ArrayOf[C::RespondTo]
51 52 53 |
# File 'lib/nanoc/core/identifiable_collection.rb', line 51 def to_a @objects.to_a end |