class Brainstem::ApiDocs::PresenterCollection

Attributes

include_internal[RW]
presenter_constant_lookup_method[W]

Public Instance Methods

create_from_presenter_collection(target_class, const) click to toggle source
# File lib/brainstem/api_docs/presenter_collection.rb, line 57
def create_from_presenter_collection(target_class, const)
  ::Brainstem::ApiDocs::Presenter.new(atlas,
    target_class:     target_class,
    const:            const,
    include_internal: include_internal
  ).tap { |p| self.<< p }
end
create_from_target_class(target_class) click to toggle source

Creates a new Presenter wrapper and appends it to the collection. If the constant lookup for the actual presenter class fails, returns nil.

# File lib/brainstem/api_docs/presenter_collection.rb, line 40
def create_from_target_class(target_class)
  ::Brainstem::ApiDocs::Presenter.new(atlas,
    target_class:     target_class,
    const:            target_class_to_const(target_class),
    include_internal: include_internal
  ).tap { |p| self.<< p }
rescue KeyError
  nil
end
find_by_target_class(target_class) click to toggle source

Finds a presenter for the given class

# File lib/brainstem/api_docs/presenter_collection.rb, line 32
def find_by_target_class(target_class)
  find { |p| p.target_class == target_class }
end
find_or_create_by_presenter_collection(target_class, const)
find_or_create_by_target_class(target_class)
find_or_create_from_presenter_collection(target_class, const) click to toggle source
# File lib/brainstem/api_docs/presenter_collection.rb, line 50
def find_or_create_from_presenter_collection(target_class, const)
    find_by_target_class(target_class) ||
      create_from_presenter_collection(target_class, const)
end
find_or_create_from_target_class(target_class) click to toggle source

Finds or creates a presenter with the given target class and appends it to the members list if it is new.

# File lib/brainstem/api_docs/presenter_collection.rb, line 22
def find_or_create_from_target_class(target_class)
  find_by_target_class(target_class) ||
    create_from_target_class(target_class)
end
valid_options() click to toggle source
# File lib/brainstem/api_docs/presenter_collection.rb, line 11
def valid_options
  super | [ :presenter_constant_lookup_method, :include_internal ]
end

Private Instance Methods

presenter_constant_lookup_method() click to toggle source

A callable method by which presenter constants can be looked up from their human name.

In future, it might be worth unifying this method with `find_by_class` to reduce total surface.

# File lib/brainstem/api_docs/presenter_collection.rb, line 84
def presenter_constant_lookup_method
  @presenter_constant_lookup_method ||= Brainstem.presenter_collection.presenters.method(:fetch)
end
target_class_to_const(target_class) click to toggle source

Converts a target class into a presenter constant. Raises an error if not found.

# File lib/brainstem/api_docs/presenter_collection.rb, line 73
def target_class_to_const(target_class)
  presenter_constant_lookup_method.call(target_class.to_s)
end