Class: Brainstem::ApiDocs::PresenterCollection

Inherits:
AbstractCollection show all
Includes:
Concerns::Formattable
Defined in:
lib/brainstem/api_docs/presenter_collection.rb

Instance Attribute Summary collapse

Attributes included from Concerns::Formattable

#formatters

Attributes inherited from AbstractCollection

#atlas

Instance Method Summary collapse

Methods included from Concerns::Formattable

#formatted_as, #formatter_type

Methods inherited from AbstractCollection

#<<, #each, #each_filename, #each_formatted, #each_formatted_with_filename, #filenames, #formatted, #formatted_with_filename, #initialize, #last, with_members

Methods included from Concerns::Optional

#initialize

Constructor Details

This class inherits a constructor from Brainstem::ApiDocs::AbstractCollection

Instance Attribute Details

#include_internalObject

Returns the value of attribute include_internal.



16
17
18
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 16

def include_internal
  @include_internal
end

#presenter_constant_lookup_method=(value) ⇒ Object

Sets the attribute presenter_constant_lookup_method

Parameters:

  • value

    the value to set the attribute presenter_constant_lookup_method to.



15
16
17
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 15

def presenter_constant_lookup_method=(value)
  @presenter_constant_lookup_method = value
end

Instance Method Details

#create_from_presenter_collection(target_class, const) ⇒ Object



57
58
59
60
61
62
63
# 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) ⇒ Object

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



40
41
42
43
44
45
46
47
48
# 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) ⇒ Object

Finds a presenter for the given class



32
33
34
# 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_from_presenter_collection(target_class, const) ⇒ Object Also known as: find_or_create_by_presenter_collection



50
51
52
53
# 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) ⇒ Object Also known as: find_or_create_by_target_class

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



22
23
24
25
# 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_optionsObject



11
12
13
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 11

def valid_options
  super | [ :presenter_constant_lookup_method, :include_internal ]
end