Class: DelegatedPresenter::Base Abstract
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- DelegatedPresenter::Base
- Defined in:
- lib/delegated_presenter/base.rb
Overview
This class is abstract.
Inherit from it to create a presenter.
Class Attribute Summary collapse
-
.exposed_methods ⇒ Object
writeonly
Sets the attribute exposed_methods.
-
.hidden_methods ⇒ Object
writeonly
Sets the attribute hidden_methods.
-
.presentable ⇒ Object
writeonly
Sets the attribute presentable.
Class Method Summary collapse
-
.expose(*exposed_methods) ⇒ Object
Exposes methods to the presenter, when defined all others will be hidden.
-
.hide(*hidden_methods) ⇒ Object
Hide methods from the presenter.
-
.presents(*objects) ⇒ Object
Determine what objects what to present.
Instance Method Summary collapse
-
#class ⇒ Object
The class of the presented object.
-
#initialize(object) ⇒ Base
constructor
Initializes the presenter with an object.
-
#presenter_class ⇒ Object
The class of the presenter.
Constructor Details
#initialize(object) ⇒ Base
Initializes the presenter with an object.
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/delegated_presenter/base.rb', line 84 def initialize(object) if object.is_a?(Array) map_array(object) else raise DelegatedPresenter::Error::NotPresentable, "#{self.presenter_class} cannot present a #{object.class}" unless object_is_presentable?(object) __setobj__(object) if exposed_methods.present? expose_methods elsif hidden_methods.present? hide_methods end end end |
Class Attribute Details
.exposed_methods=(value) ⇒ Object
Sets the attribute exposed_methods
14 15 16 |
# File 'lib/delegated_presenter/base.rb', line 14 def exposed_methods=(value) @exposed_methods = value end |
.hidden_methods=(value) ⇒ Object
Sets the attribute hidden_methods
14 15 16 |
# File 'lib/delegated_presenter/base.rb', line 14 def hidden_methods=(value) @hidden_methods = value end |
.presentable=(value) ⇒ Object
Sets the attribute presentable
14 15 16 |
# File 'lib/delegated_presenter/base.rb', line 14 def presentable=(value) @presentable = value end |
Class Method Details
.expose(*exposed_methods) ⇒ Object
Exposes methods to the presenter, when defined all others will be hidden.
61 62 63 |
# File 'lib/delegated_presenter/base.rb', line 61 def expose(*exposed_methods) self.exposed_methods += exposed_methods.flatten end |
.hide(*hidden_methods) ⇒ Object
Hide methods from the presenter.
52 53 54 |
# File 'lib/delegated_presenter/base.rb', line 52 def hide(*hidden_methods) self.hidden_methods += hidden_methods end |
.presents(*objects) ⇒ Object
Determine what objects what to present.
43 44 45 |
# File 'lib/delegated_presenter/base.rb', line 43 def presents(*objects) self.presentable += objects.flatten.collect{ |i| i.to_s.camelize.singularize } end |
Instance Method Details
#class ⇒ Object
The class of the presented object.
102 103 104 |
# File 'lib/delegated_presenter/base.rb', line 102 def class presented_model.class end |
#presenter_class ⇒ Object
The class of the presenter.
99 |
# File 'lib/delegated_presenter/base.rb', line 99 alias_method :presenter_class, :class |