Class: Carnival::Action
- Inherits:
-
Object
- Object
- Carnival::Action
- Defined in:
- app/models/carnival/action.rb
Direct Known Subclasses
Constant Summary collapse
- PARTIAL_DEFAULT =
:default
- PARTIAL_DELETE =
:delete
- PARTIAL_REMOTE =
:remote
Instance Method Summary collapse
- #default_partial ⇒ Object
-
#initialize(name, params = {}) ⇒ Action
constructor
A new instance of Action.
- #name ⇒ Object
- #params ⇒ Object
- #partial ⇒ Object
- #path(presenter, extra_params = {}) ⇒ Object
- #remote? ⇒ Boolean
- #show(record) ⇒ Object
- #target ⇒ Object
Constructor Details
#initialize(name, params = {}) ⇒ Action
Returns a new instance of Action.
8 9 10 11 12 13 14 15 |
# File 'app/models/carnival/action.rb', line 8 def initialize(name, params={}) @name = name @params = params @partial = default_partial @path = params[:path] if params[:path].present? @controller = params[:controller] @route_name = params[:route_name] end |
Instance Method Details
#default_partial ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/carnival/action.rb', line 61 def default_partial() if [:new, :edit, :show].include?(@name) PARTIAL_DEFAULT elsif @name == :destroy PARTIAL_DELETE elsif remote? PARTIAL_REMOTE else PARTIAL_DEFAULT end end |
#name ⇒ Object
48 49 50 |
# File 'app/models/carnival/action.rb', line 48 def name @name end |
#params ⇒ Object
44 45 46 |
# File 'app/models/carnival/action.rb', line 44 def params @params end |
#partial ⇒ Object
40 41 42 |
# File 'app/models/carnival/action.rb', line 40 def partial @partial end |
#path(presenter, extra_params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/carnival/action.rb', line 17 def path(presenter, extra_params={}) if @path.nil? params = {controller: @controller || presenter.controller_name, action: @name} elsif !@path[:controller].nil? params = @path else params = {path: @path} end params = params.merge(extra_params) if extra_params.present? params = params.merge(:only_path => true) if @route_name Rails.application.routes.url_helpers.send(@route_name, params) else url_for(params) end end |
#remote? ⇒ Boolean
52 53 54 |
# File 'app/models/carnival/action.rb', line 52 def remote? @params[:remote] end |
#show(record) ⇒ Object
34 35 36 37 38 |
# File 'app/models/carnival/action.rb', line 34 def show(record) return true if !params[:show_func] return true if !record.respond_to? params[:show_func] record.send params[:show_func] end |
#target ⇒ Object
56 57 58 59 |
# File 'app/models/carnival/action.rb', line 56 def target return :record if @params[:target].nil? @params[:target] end |