Class: Layered::Resource::Routing::CustomActionsBuilder
- Inherits:
-
Object
- Object
- Layered::Resource::Routing::CustomActionsBuilder
- Defined in:
- lib/layered/resource/routing.rb
Overview
Collects custom member/collection routes declared inside a
layered_resources block. Mirrors the small subset of Rails'
resources block DSL we care about: nested member do ... end /
collection do ... end containing HTTP-verb action declarations.
Constant Summary collapse
- VERBS =
%i[get post patch put delete].freeze
Instance Attribute Summary collapse
-
#collection_actions ⇒ Object
readonly
Returns the value of attribute collection_actions.
-
#member_actions ⇒ Object
readonly
Returns the value of attribute member_actions.
Instance Method Summary collapse
- #collection(&block) ⇒ Object
-
#initialize ⇒ CustomActionsBuilder
constructor
A new instance of CustomActionsBuilder.
- #member(&block) ⇒ Object
- #method_missing(name, *_args, &_block) ⇒ Object
- #respond_to_missing?(_name, _include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ CustomActionsBuilder
Returns a new instance of CustomActionsBuilder.
42 43 44 45 46 |
# File 'lib/layered/resource/routing.rb', line 42 def initialize @member_actions = [] @collection_actions = [] @scope = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *_args, &_block) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/layered/resource/routing.rb', line 73 def method_missing(name, *_args, &_block) raise ArgumentError, "`#{name}` is not supported inside a layered_resources block. " \ "Only `member`, `collection`, and HTTP verbs (#{VERBS.join(', ')}) are available; " \ "declare other routes outside the block." end |
Instance Attribute Details
#collection_actions ⇒ Object (readonly)
Returns the value of attribute collection_actions.
40 41 42 |
# File 'lib/layered/resource/routing.rb', line 40 def collection_actions @collection_actions end |
#member_actions ⇒ Object (readonly)
Returns the value of attribute member_actions.
40 41 42 |
# File 'lib/layered/resource/routing.rb', line 40 def member_actions @member_actions end |
Instance Method Details
#collection(&block) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/layered/resource/routing.rb', line 55 def collection(&block) previous, @scope = @scope, :collection instance_eval(&block) ensure @scope = previous end |
#member(&block) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/layered/resource/routing.rb', line 48 def member(&block) previous, @scope = @scope, :member instance_eval(&block) ensure @scope = previous end |
#respond_to_missing?(_name, _include_private = false) ⇒ Boolean
80 81 82 |
# File 'lib/layered/resource/routing.rb', line 80 def respond_to_missing?(_name, _include_private = false) false end |