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.
-
#disable_body ⇒ Object
readonly
Returns the value of attribute disable_body.
-
#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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params_schema ⇒ Object
readonly
Returns the value of attribute params_schema.
-
#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, params_schema: nil, headers_schema: nil, metadata: {}, use: [], disable_body: false, &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, params_schema: nil, headers_schema: nil, metadata: {}, use: [], disable_body: false, &handler) ⇒ Endpoint
Returns a new instance of Endpoint.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/better_auth/endpoint.rb', line 18 def initialize(path: nil, method: nil, body_schema: nil, query_schema: nil, params_schema: nil, headers_schema: nil, metadata: {}, use: [], disable_body: false, &handler) @path = path @methods = Array(method || "*").map { |value| value.to_s.upcase } @body_schema = body_schema @query_schema = query_schema @params_schema = params_schema @headers_schema = headers_schema @metadata = || {} apply_open_api_schemas! @options = @use = Array(use) @disable_body = !!disable_body @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 |
#disable_body ⇒ Object (readonly)
Returns the value of attribute disable_body.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def disable_body @disable_body 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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def @options end |
#params_schema ⇒ Object (readonly)
Returns the value of attribute params_schema.
7 8 9 |
# File 'lib/better_auth/endpoint.rb', line 7 def params_schema @params_schema 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
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/better_auth/endpoint.rb', line 42 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
38 39 40 |
# File 'lib/better_auth/endpoint.rb', line 38 def matches_method?(method) methods.include?("*") || methods.include?(method.to_s.upcase) end |
#methods ⇒ Object
34 35 36 |
# File 'lib/better_auth/endpoint.rb', line 34 def methods @methods.empty? ? ["*"] : @methods end |