Class: OpenapiBlocks::Routing::Operation
- Inherits:
-
Object
- Object
- OpenapiBlocks::Routing::Operation
- Defined in:
- lib/openapi_blocks/routing/operation.rb
Overview
rubocop:disable Style/Documentation
Constant Summary collapse
- ACTIONS_MAP =
{ "index" => { verbs: ["get"], has_body: false }, "show" => { verbs: ["get"], has_body: false }, "create" => { verbs: ["post"], has_body: true }, "update" => { verbs: %w[put patch], has_body: true }, "destroy" => { verbs: ["delete"], has_body: false } }.freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#has_body ⇒ Object
readonly
Returns the value of attribute has_body.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#verbs ⇒ Object
readonly
Returns the value of attribute verbs.
Instance Method Summary collapse
-
#initialize(route) ⇒ Operation
constructor
A new instance of Operation.
- #path_parameters ⇒ Object
- #schema_name ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(route) ⇒ Operation
Returns a new instance of Operation.
16 17 18 19 20 21 22 |
# File 'lib/openapi_blocks/routing/operation.rb', line 16 def initialize(route) @controller = route[:controller] @action = route[:action] @path = normalize_path(route[:path]) @verbs = ACTIONS_MAP.dig(@action, :verbs) @has_body = ACTIONS_MAP.dig(@action, :has_body) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
14 15 16 |
# File 'lib/openapi_blocks/routing/operation.rb', line 14 def action @action end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
14 15 16 |
# File 'lib/openapi_blocks/routing/operation.rb', line 14 def controller @controller end |
#has_body ⇒ Object (readonly)
Returns the value of attribute has_body.
14 15 16 |
# File 'lib/openapi_blocks/routing/operation.rb', line 14 def has_body @has_body end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/openapi_blocks/routing/operation.rb', line 14 def path @path end |
#verbs ⇒ Object (readonly)
Returns the value of attribute verbs.
14 15 16 |
# File 'lib/openapi_blocks/routing/operation.rb', line 14 def verbs @verbs end |
Instance Method Details
#path_parameters ⇒ Object
28 29 30 |
# File 'lib/openapi_blocks/routing/operation.rb', line 28 def path_parameters @path.scan(/\{(\w+)\}/).flatten end |
#schema_name ⇒ Object
32 33 34 |
# File 'lib/openapi_blocks/routing/operation.rb', line 32 def schema_name @controller.split("/").last.classify end |
#valid? ⇒ Boolean
24 25 26 |
# File 'lib/openapi_blocks/routing/operation.rb', line 24 def valid? ACTIONS_MAP.key?(@action) && @verbs.present? end |