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.
22 23 24 25 26 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 22 def initialize(atlas, = {}) self.atlas = atlas self.members = [] super end |
Instance Attribute Details
#atlas ⇒ Object
Returns the value of attribute atlas.
28 29 30 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 28 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.
42 43 44 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 42 def <<(*objects) members.push(*objects.flatten) end |
#each(&block) ⇒ Object
Iterates over each controller in the collection.
49 50 51 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 49 def each(&block) members.each(&block) end |
#each_filename(format, &block) ⇒ Object
92 93 94 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 92 def each_filename(format, &block) filenames(format).each { |args| block.call(*args) } end |
#each_formatted(format, options = {}, &block) ⇒ Object
87 88 89 90 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 87 def each_formatted(format, = {}, &block) formatted(format, ) .each { |args| block.call(*args) } end |
#each_formatted_with_filename(format, options = {}, &block) ⇒ Object
82 83 84 85 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 82 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).
67 68 69 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 67 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.
56 57 58 59 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 56 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.
74 75 76 77 78 79 80 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 74 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.
35 36 37 |
# File 'lib/brainstem/api_docs/abstract_collection.rb', line 35 def last members[-1] end |