Class: Cathode::Action
- Inherits:
-
Object
- Object
- Cathode::Action
- Includes:
- ActionDsl
- Defined in:
- lib/cathode/action.rb
Overview
Direct Known Subclasses
CreateAction, CustomAction, DestroyAction, IndexAction, ShowAction, UpdateAction
Defined Under Namespace
Modules: RequiresAssociation, RequiresCustomActionForSingular, RequiresHasManyAssociation, RequiresHasOneAssociation, RequiresStrongParams
Instance Attribute Summary collapse
-
#action_access_filter ⇒ Object
readonly
Returns the value of attribute action_access_filter.
-
#action_block ⇒ Object
readonly
Returns the value of attribute action_block.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#override_block ⇒ Object
readonly
Returns the value of attribute override_block.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#strong_params ⇒ Object
Returns the value of attribute strong_params.
Class Method Summary collapse
-
.create(action, resource, params = nil, &block) ⇒ IndexAction, ...
Creates an action by initializing the appropriate subclass.
Instance Method Summary collapse
-
#allowed?(subaction) ⇒ Boolean
Whether a subaction is permitted.
-
#initialize(action, resource, params = {}, &block) ⇒ Action
constructor
Initializes the action.
Methods included from ActionDsl
#actions, #custom_actions, #default_actions
Constructor Details
#initialize(action, resource, params = {}, &block) ⇒ Action
Initializes the action
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cathode/action.rb', line 50 def initialize(action, resource, params = {}, &block) @name, @resource = action, resource @allowed_subactions = [] if block_given? if params[:override] override &block else if [:index, :show, :create, :update, :destroy].include? action instance_eval &block else @action_block = block end end end @http_method = params[:method] if params.present? after_initialize if respond_to? :after_initialize end |
Instance Attribute Details
#action_access_filter ⇒ Object (readonly)
Returns the value of attribute action_access_filter.
9 10 11 |
# File 'lib/cathode/action.rb', line 9 def action_access_filter @action_access_filter end |
#action_block ⇒ Object (readonly)
Returns the value of attribute action_block.
9 10 11 |
# File 'lib/cathode/action.rb', line 9 def action_block @action_block end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
9 10 11 |
# File 'lib/cathode/action.rb', line 9 def http_method @http_method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/cathode/action.rb', line 9 def name @name end |
#override_block ⇒ Object (readonly)
Returns the value of attribute override_block.
9 10 11 |
# File 'lib/cathode/action.rb', line 9 def override_block @override_block end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
9 10 11 |
# File 'lib/cathode/action.rb', line 9 def resource @resource end |
#strong_params ⇒ Object
Returns the value of attribute strong_params.
8 9 10 |
# File 'lib/cathode/action.rb', line 8 def strong_params @strong_params end |
Class Method Details
.create(action, resource, params = nil, &block) ⇒ IndexAction, ...
Creates an action by initializing the appropriate subclass
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cathode/action.rb', line 26 def create(action, resource, params = nil, &block) klass = case action when :index IndexAction when :show ShowAction when :create CreateAction when :update UpdateAction when :destroy DestroyAction else CustomAction end klass.new(action, resource, params, &block) end |
Instance Method Details
#allowed?(subaction) ⇒ Boolean
Whether a subaction is permitted
74 75 76 |
# File 'lib/cathode/action.rb', line 74 def allowed?(subaction) @allowed_subactions.include? subaction end |