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

#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



55
56
57
58
59
60
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 55

def create_from_presenter_collection(target_class, const)
  ::Brainstem::ApiDocs::Presenter.new(atlas,
    target_class: target_class,
    const:        const
  ).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.



39
40
41
42
43
44
45
46
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 39

def create_from_target_class(target_class)
  ::Brainstem::ApiDocs::Presenter.new(atlas,
    target_class: target_class,
    const:        target_class_to_const(target_class)
  ).tap { |p| self.<< p }
rescue KeyError
  nil
end

#find_by_target_class(target_class) ⇒ Object

Finds a presenter for the given class



31
32
33
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 31

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



48
49
50
51
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 48

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.



21
22
23
24
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 21

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 ]
end