class Brainstem::ApiDocs::AbstractCollection
Attributes
atlas[RW]
members[RW]
Public Class Methods
new(atlas, options = {})
click to toggle source
Calls superclass method
Brainstem::Concerns::Optional::new
# File lib/brainstem/api_docs/abstract_collection.rb, line 22 def initialize(atlas, options = {}) self.atlas = atlas self.members = [] super options end
with_members(atlas, *members)
click to toggle source
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.
# 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
Public Instance Methods
<<(*objects)
click to toggle source
Appends a pre-existing object to the collection.
# File lib/brainstem/api_docs/abstract_collection.rb, line 42 def <<(*objects) members.push(*objects.flatten) end
each(&block)
click to toggle source
Iterates over each controller in the collection.
# File lib/brainstem/api_docs/abstract_collection.rb, line 49 def each(&block) members.each(&block) end
each_filename(format, &block)
click to toggle source
# 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)
click to toggle source
# File lib/brainstem/api_docs/abstract_collection.rb, line 87 def each_formatted(format, options = {}, &block) formatted(format, options) .each { |args| block.call(*args) } end
each_formatted_with_filename(format, options = {}, &block)
click to toggle source
# File lib/brainstem/api_docs/abstract_collection.rb, line 82 def each_formatted_with_filename(format, options = {}, &block) formatted_with_filename(format, options) .each { |args| block.call(*args) } end
filenames(format)
click to toggle source
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).
# 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 = {})
click to toggle source
Returns a map of each member formatted as specified.
# File lib/brainstem/api_docs/abstract_collection.rb, line 56 def formatted(format, options = {}) map { |member| member.formatted_as(format, options) } .reject(&:empty?) end
formatted_with_filename(format, options = {})
click to toggle source
Returns a map of each formatted member and its suggested filename.
# File lib/brainstem/api_docs/abstract_collection.rb, line 74 def formatted_with_filename(format, options = {}) map { |member| [ member.formatted_as(format, options), member.suggested_filename(format) ] } .reject { |(buffer, _)| buffer.empty? } end
last()
click to toggle source
Handy accessor for extracting the last member of the collection.
# File lib/brainstem/api_docs/abstract_collection.rb, line 35 def last members[-1] end