Class: Layered::Resource::Routing::CustomActionsBuilder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeCustomActionsBuilder

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

Raises:

  • (ArgumentError)


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_actionsObject (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_actionsObject (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

Returns:

  • (Boolean)


80
81
82
# File 'lib/layered/resource/routing.rb', line 80

def respond_to_missing?(_name, _include_private = false)
  false
end