Class: BetterAuth::Endpoint
- Inherits:
-
Object
- Object
- BetterAuth::Endpoint
- Defined in:
- lib/better_auth/endpoint.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#body_schema ⇒ Object
readonly
Returns the value of attribute body_schema.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#headers_schema ⇒ Object
readonly
Returns the value of attribute headers_schema.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query_schema ⇒ Object
readonly
Returns the value of attribute query_schema.
-
#use ⇒ Object
readonly
Returns the value of attribute use.
Instance Method Summary collapse
- #call(context) ⇒ Object
-
#initialize(path: nil, method: nil, body_schema: nil, query_schema: nil, headers_schema: nil, metadata: {}, use: [], &handler) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #matches_method?(method) ⇒ Boolean
- #methods ⇒ Object
Constructor Details
#initialize(path: nil, method: nil, body_schema: nil, query_schema: nil, headers_schema: nil, metadata: {}, use: [], &handler) ⇒ Endpoint
Returns a new instance of Endpoint.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/better_auth/endpoint.rb', line 15 def initialize(path: nil, method: nil, body_schema: nil, query_schema: nil, headers_schema: nil, metadata: {}, use: [], &handler) @path = path @methods = Array(method || "*").map { |value| value.to_s.upcase } @body_schema = body_schema @query_schema = query_schema @headers_schema = headers_schema @metadata = || {} @use = Array(use) @handler = handler || ->(_ctx) {} end |
Instance Attribute Details
#body_schema ⇒ Object (readonly)
Returns the value of attribute body_schema.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def body_schema @body_schema end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def handler @handler end |
#headers_schema ⇒ Object (readonly)
Returns the value of attribute headers_schema.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def headers_schema @headers_schema end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def path @path end |
#query_schema ⇒ Object (readonly)
Returns the value of attribute query_schema.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def query_schema @query_schema end |
#use ⇒ Object (readonly)
Returns the value of attribute use.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def use @use end |
Instance Method Details
#call(context) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/better_auth/endpoint.rb', line 34 def call(context) apply_schemas!(context) use.each do |middleware| middleware_result = middleware.call(context) return Result.from_value(middleware_result, context) if middleware_result end Result.from_value(handler.call(context), context) end |
#matches_method?(method) ⇒ Boolean
30 31 32 |
# File 'lib/better_auth/endpoint.rb', line 30 def matches_method?(method) methods.include?("*") || methods.include?(method.to_s.upcase) end |
#methods ⇒ Object
26 27 28 |
# File 'lib/better_auth/endpoint.rb', line 26 def methods @methods.empty? ? ["*"] : @methods end |