Class: Presenters::BatchSubmenuPresenter
- Inherits:
-
Object
- Object
- Presenters::BatchSubmenuPresenter
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/models/presenters/batch_submenu_presenter.rb
Overview
The Batch show page in the BatchesController has a side menu which displays a variety of options depending on properties of the batch. The BatchSubmenuPresenter encapsulates the logic which was previously in the view itself.
Instance Attribute Summary collapse
-
#ability ⇒ Object
readonly
Returns the value of attribute ability.
-
#batch ⇒ Object
readonly
Returns the value of attribute batch.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pipeline ⇒ Object
readonly
Returns the value of attribute pipeline.
Instance Method Summary collapse
- #add_submenu_option(text, action_params) ⇒ Object
- #each_option ⇒ Object
-
#initialize(current_user, batch) ⇒ BatchSubmenuPresenter
constructor
A new instance of BatchSubmenuPresenter.
Constructor Details
#initialize(current_user, batch) ⇒ BatchSubmenuPresenter
Returns a new instance of BatchSubmenuPresenter.
19 20 21 22 23 24 25 26 |
# File 'app/models/presenters/batch_submenu_presenter.rb', line 19 def initialize(current_user, batch) @current_user = current_user @ability = Ability.new(current_user) @batch = batch @pipeline = @batch.pipeline @defaults = { controller: :batches, id: @batch.id, only_path: true } end |
Instance Attribute Details
#ability ⇒ Object (readonly)
Returns the value of attribute ability.
8 9 10 |
# File 'app/models/presenters/batch_submenu_presenter.rb', line 8 def ability @ability end |
#batch ⇒ Object (readonly)
Returns the value of attribute batch.
8 9 10 |
# File 'app/models/presenters/batch_submenu_presenter.rb', line 8 def batch @batch end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'app/models/presenters/batch_submenu_presenter.rb', line 8 def @options end |
#pipeline ⇒ Object (readonly)
Returns the value of attribute pipeline.
8 9 10 |
# File 'app/models/presenters/batch_submenu_presenter.rb', line 8 def pipeline @pipeline end |
Instance Method Details
#add_submenu_option(text, action_params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/presenters/batch_submenu_presenter.rb', line 28 def (text, action_params) @options ||= [] # If it is a string, it will be an url unless action_params.is_a?(String) # If it is a symbol, it will be the action # If not, it will be a Hash with the new content (controller, action, ...) action_params = { action: action_params } if action_params.is_a?(Symbol) action_config = @defaults.dup action_params.each_pair { |key, value| action_config[key] = value } action_params = url_for(action_config) end @options += [{ label: text, url: action_params }] end |
#each_option ⇒ Object
43 44 45 46 |
# File 'app/models/presenters/batch_submenu_presenter.rb', line 43 def each_option(&) if @options.nil? @options.each(&) end |