Class: MetaPresenter::Builder
- Inherits:
-
Object
- Object
- MetaPresenter::Builder
- Defined in:
- lib/meta_presenter/builder.rb
Overview
Builds a presenter class for a controller and method
Defined Under Namespace
Classes: FileExistsButPresenterNotDefinedError, InvalidControllerError
Instance Attribute Summary collapse
-
#action_name ⇒ String
readonly
Name of the controller’s action to hook the presenter up to.
-
#controller ⇒ ActionController::Base, ActionMailer::Base
readonly
Controller that this presenter will delegate methods to.
Instance Method Summary collapse
-
#initialize(controller, action_name) ⇒ Builder
constructor
Creates a new Builder.
- #presenter_base_dir ⇒ Object
-
#presenter_class ⇒ Class
Class constant for the built MetaPresenter::Base presenter.
Constructor Details
#initialize(controller, action_name) ⇒ Builder
Creates a new Builder
16 17 18 19 |
# File 'lib/meta_presenter/builder.rb', line 16 def initialize(controller, action_name) @controller = controller @action_name = action_name end |
Instance Attribute Details
#action_name ⇒ String (readonly)
Returns Name of the controller’s action to hook the presenter up to.
10 11 12 |
# File 'lib/meta_presenter/builder.rb', line 10 def action_name @action_name end |
#controller ⇒ ActionController::Base, ActionMailer::Base (readonly)
Returns Controller that this presenter will delegate methods to.
7 8 9 |
# File 'lib/meta_presenter/builder.rb', line 7 def controller @controller end |
Instance Method Details
#presenter_base_dir ⇒ Object
53 54 55 |
# File 'lib/meta_presenter/builder.rb', line 53 def presenter_base_dir File.join(Rails.root, 'app', 'presenters') end |
#presenter_class ⇒ Class
Returns Class constant for the built MetaPresenter::Base presenter.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/meta_presenter/builder.rb', line 40 def presenter_class # Try to find the presenter class (Not guaranteed, # for example if the presenter class wasn't defined # or if the file wasn't found) klass = nil ancestors.each do |klass_name| klass = presenter_class_for(klass_name) break unless klass.nil? end klass end |