Class: Brainstem::ApiDocs::PresenterCollection
- Inherits:
-
AbstractCollection
- Object
- AbstractCollection
- Brainstem::ApiDocs::PresenterCollection
- Includes:
- Concerns::Formattable
- Defined in:
- lib/brainstem/api_docs/presenter_collection.rb
Instance Attribute Summary collapse
-
#presenter_constant_lookup_method ⇒ Object
writeonly
Sets the attribute presenter_constant_lookup_method.
Attributes included from Concerns::Formattable
Attributes inherited from AbstractCollection
Instance Method Summary collapse
- #create_from_presenter_collection(target_class, const) ⇒ Object
-
#create_from_target_class(target_class) ⇒ Object
Creates a new
Presenter
wrapper and appends it to the collection. -
#find_by_target_class(target_class) ⇒ Object
Finds a presenter for the given class.
- #find_or_create_from_presenter_collection(target_class, const) ⇒ Object (also: #find_or_create_by_presenter_collection)
-
#find_or_create_from_target_class(target_class) ⇒ Object
(also: #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.
- #valid_options ⇒ Object
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
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
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_options ⇒ Object
11 12 13 |
# File 'lib/brainstem/api_docs/presenter_collection.rb', line 11 def super | [ :presenter_constant_lookup_method ] end |