Class: Archipelago::Action
- Inherits:
-
Object
- Object
- Archipelago::Action
- Includes:
- ParamsDSL
- Defined in:
- lib/archipelago/action.rb
Constant Summary
Constants included from ParamsDSL
Class Attribute Summary collapse
-
.authorization_block ⇒ Object
readonly
Returns the value of attribute authorization_block.
Instance Attribute Summary collapse
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#raw_params ⇒ Object
readonly
Returns the value of attribute raw_params.
Class Method Summary collapse
Instance Method Summary collapse
- #add_error(field, message) ⇒ Object
- #call ⇒ Object
-
#initialize(ctx:, raw_params:) ⇒ Action
constructor
A new instance of Action.
- #props(payload) ⇒ Object
- #redirect_to(location) ⇒ Object
Methods included from ParamsDSL
#coerce_declared_params, included
Constructor Details
#initialize(ctx:, raw_params:) ⇒ Action
Returns a new instance of Action.
17 18 19 20 21 22 23 24 |
# File 'lib/archipelago/action.rb', line 17 def initialize(ctx:, raw_params:) @ctx = ctx @raw_params = raw_params.with_indifferent_access @errors = Hash.new { |hash, key| hash[key] = [] } @coerced_params = {} @response_props = {} @redirect_location = nil end |
Class Attribute Details
.authorization_block ⇒ Object (readonly)
Returns the value of attribute authorization_block.
8 9 10 |
# File 'lib/archipelago/action.rb', line 8 def @authorization_block end |
Instance Attribute Details
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
15 16 17 |
# File 'lib/archipelago/action.rb', line 15 def ctx @ctx end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/archipelago/action.rb', line 15 def errors @errors end |
#raw_params ⇒ Object (readonly)
Returns the value of attribute raw_params.
15 16 17 |
# File 'lib/archipelago/action.rb', line 15 def raw_params @raw_params end |
Class Method Details
.authorize(&block) ⇒ Object
10 11 12 |
# File 'lib/archipelago/action.rb', line 10 def (&block) @authorization_block = block end |
Instance Method Details
#add_error(field, message) ⇒ Object
66 67 68 |
# File 'lib/archipelago/action.rb', line 66 def add_error(field, ) errors[field.to_s] << end |
#call ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/archipelago/action.rb', line 26 def call Archipelago.instrument("archipelago.action.perform", action: self.class.name) do @coerced_params, coercion_errors = coerce_declared_params(raw_params) merge_errors!(coercion_errors) if errors.any? Archipelago.instrument("archipelago.action.error", action: self.class.name, reason: "validation") return Archipelago::Response.error(errors: errors) end perform if errors.any? Archipelago.instrument("archipelago.action.error", action: self.class.name, reason: "validation") return Archipelago::Response.error(errors: errors) end if @redirect_location validator = Archipelago::Security::RedirectValidator.new location = validator.validate!(@redirect_location) return Archipelago::Response.redirect(location: location) end payload = Archipelago::Response.ok(props: @response_props, version: Archipelago.next_version) maybe_broadcast(payload) payload end rescue Archipelago::Forbidden Archipelago.instrument("archipelago.action.error", action: self.class.name, reason: "forbidden") Archipelago::Response.forbidden rescue StandardError => e if record_invalid_error?(e) map_record_invalid!(e) Archipelago.instrument("archipelago.action.error", action: self.class.name, reason: "record_invalid") Archipelago::Response.error(errors: errors) else raise end end |
#props(payload) ⇒ Object
70 71 72 |
# File 'lib/archipelago/action.rb', line 70 def props(payload) @response_props = payload end |
#redirect_to(location) ⇒ Object
74 75 76 |
# File 'lib/archipelago/action.rb', line 74 def redirect_to(location) @redirect_location = location end |