Class: Cathode::Action
- Inherits:
-
Object
- Object
- Cathode::Action
- Defined in:
- lib/cathode/action.rb
Direct Known Subclasses
CreateAction, DestroyAction, IndexAction, ShowAction, UpdateAction
Instance Attribute Summary collapse
-
#action_access_filter ⇒ Object
readonly
Returns the value of attribute action_access_filter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(action, resource, &block) ⇒ Action
constructor
A new instance of Action.
- #perform(params) ⇒ Object
Constructor Details
#initialize(action, resource, &block) ⇒ Action
Returns a new instance of Action.
24 25 26 27 28 |
# File 'lib/cathode/action.rb', line 24 def initialize(action, resource, &block) @name, @resource = action, resource self.instance_eval &block if block_given? end |
Instance Attribute Details
#action_access_filter ⇒ Object (readonly)
Returns the value of attribute action_access_filter.
3 4 5 |
# File 'lib/cathode/action.rb', line 3 def action_access_filter @action_access_filter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/cathode/action.rb', line 3 def name @name end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
3 4 5 |
# File 'lib/cathode/action.rb', line 3 def resource @resource end |
Class Method Details
.create(action, resource, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cathode/action.rb', line 8 def self.create(action, resource, &block) klass = case action when :index IndexAction when :show ShowAction when :create CreateAction when :update UpdateAction when :destroy DestroyAction end klass.new(action, resource, &block) end |
Instance Method Details
#perform(params) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/cathode/action.rb', line 30 def perform(params) if action_access_filter && !action_access_filter.call return { status: :unauthorized } end body = perform_action params return { body: body, status: :ok } end |