Class: Brainstem::ApiDocs::AbstractCollection
- Inherits:
-
Object
- Object
- Brainstem::ApiDocs::AbstractCollection
- Extended by:
- Forwardable
- Includes:
- Concerns::Formattable, Concerns::Optional, Enumerable
- Defined in:
- lib/brainstem/api_docs/abstract_collection.rb
Direct Known Subclasses
ControllerCollection, EndpointCollection, PresenterCollection
Instance Attribute Summary collapse
-
#atlas ⇒ Object
Returns the value of attribute atlas.
Attributes included from Concerns::Formattable
Class Method Summary collapse
-
.with_members(atlas, *members) ⇒ Object
Creates a new collection with all passed members.
Instance Method Summary collapse
-
#<<(*objects) ⇒ Object
Appends a pre-existing object to the collection.
-
#each(&block) ⇒ Object
Iterates over each controller in the collection.
- #each_filename(format, &block) ⇒ Object
- #each_formatted(format, options = {}, &block) ⇒ Object
- #each_formatted_with_filename(format, options = {}, &block) ⇒ Object
-
#filenames(format) ⇒ Object
Returns a list of each member’s filename.
-
#formatted(format, options = {}) ⇒ Object
Returns a map of each member formatted as specified.
-
#formatted_with_filename(format, options = {}) ⇒ Object
Returns a map of each formatted member and its suggested filename.
-
#initialize(atlas, options = {}) ⇒ AbstractCollection
constructor
A new instance of AbstractCollection.
-
#last ⇒ Object
Handy accessor for extracting the last member of the collection.
Methods included from Concerns::Formattable
#formatted_as, #formatter_type, #valid_options
Methods included from Concerns::Optional
Constructor Details
#initialize(atlas, options = {}) ⇒ AbstractCollection
Returns a new instance of AbstractCollection.
23 24 25 26 27 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 23 def initialize(atlas, = {}) self.atlas = atlas self.members = [] super end |
Instance Attribute Details
#atlas ⇒ Object
Returns the value of attribute atlas.
30 31 32 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 30 def atlas @atlas end |
Class Method Details
.with_members(atlas, *members) ⇒ Object
Creates a new collection with all passed members. Very handy for reduce operations which should return a subset of members but retain the same utility.
18 19 20 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 18 def self.with_members(atlas, *members) new(atlas).tap {|n| members.flatten.each { |m| n << m } } end |
Instance Method Details
#<<(*objects) ⇒ Object
Appends a pre-existing object to the collection.
46 47 48 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 46 def <<(*objects) members.push(*objects.flatten) end |
#each(&block) ⇒ Object
Iterates over each controller in the collection.
54 55 56 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 54 def each(&block) members.each(&block) end |
#each_filename(format, &block) ⇒ Object
103 104 105 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 103 def each_filename(format, &block) filenames(format).each { |args| block.call(*args) } end |
#each_formatted(format, options = {}, &block) ⇒ Object
97 98 99 100 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 97 def each_formatted(format, = {}, &block) formatted(format, ) .each { |args| block.call(*args) } end |
#each_formatted_with_filename(format, options = {}, &block) ⇒ Object
91 92 93 94 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 91 def each_formatted_with_filename(format, = {}, &block) formatted_with_filename(format, ) .each { |args| block.call(*args) } end |
#filenames(format) ⇒ Object
Returns a list of each member’s filename.
We internally refer to ‘formatted_with_filename` here because we don’t want to include any filenames of empty files (i.e. nodoc).
74 75 76 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 74 def filenames(format) formatted_with_filename(format).map { |arr| arr[1] } end |
#formatted(format, options = {}) ⇒ Object
Returns a map of each member formatted as specified.
62 63 64 65 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 62 def formatted(format, = {}) map { |member| member.formatted_as(format, ) } .reject(&:empty?) end |
#formatted_with_filename(format, options = {}) ⇒ Object
Returns a map of each formatted member and its suggested filename.
82 83 84 85 86 87 88 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 82 def formatted_with_filename(format, = {}) map { |member| [ member.formatted_as(format, ), member.suggested_filename(format) ] } .reject { |(buffer, _)| buffer.empty? } end |
#last ⇒ Object
Handy accessor for extracting the last member of the collection.
38 39 40 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 38 def last members[-1] end |