Class: BetterAuth::Context
- Inherits:
-
Object
- Object
- BetterAuth::Context
- Defined in:
- lib/better_auth/context.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#auth_cookies ⇒ Object
readonly
Returns the value of attribute auth_cookies.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#current_session ⇒ Object
readonly
Returns the value of attribute current_session.
-
#internal_adapter ⇒ Object
readonly
Returns the value of attribute internal_adapter.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#new_session ⇒ Object
readonly
Returns the value of attribute new_session.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rate_limit_config ⇒ Object
readonly
Returns the value of attribute rate_limit_config.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#session_config ⇒ Object
readonly
Returns the value of attribute session_config.
-
#social_providers ⇒ Object
readonly
Returns the value of attribute social_providers.
-
#trusted_origins ⇒ Object
readonly
Returns the value of attribute trusted_origins.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #apply_plugin_context!(attributes) ⇒ Object
- #create_auth_cookie(cookie_name, override_attributes = {}) ⇒ Object
-
#initialize(configuration) ⇒ Context
constructor
A new instance of Context.
- #method_missing(name, *arguments, &block) ⇒ Object
- #prepare_for_request!(request) ⇒ Object
- #refresh_from_options! ⇒ Object
- #reset_runtime! ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
- #run_in_background(task) ⇒ Object
- #set_adapter(adapter) ⇒ Object
- #set_current_session(session) ⇒ Object
- #set_internal_adapter(adapter) ⇒ Object
- #set_new_session(session) ⇒ Object
- #trusted_origin?(url, allow_relative_paths: false) ⇒ Boolean
Constructor Details
#initialize(configuration) ⇒ Context
Returns a new instance of Context.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/better_auth/context.rb', line 24 def initialize(configuration) @app_name = configuration.app_name @base_url = configuration.context_base_url @version = BetterAuth::VERSION @options = configuration @social_providers = configuration. @auth_cookies = Cookies.(configuration) @cookies = @auth_cookies @adapter = configuration.database @internal_adapter = nil @logger = configuration.logger @session_config = configuration.session @rate_limit_config = configuration.rate_limit @trusted_origins = configuration.trusted_origins @secret = configuration.secret @current_session = nil @new_session = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, &block) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/better_auth/context.rb', line 92 def method_missing(name, *arguments, &block) variable_name = :"@#{name}" return instance_variable_get(variable_name) if arguments.empty? && instance_variable_defined?(variable_name) super end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def adapter @adapter end |
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def app_name @app_name end |
#auth_cookies ⇒ Object (readonly)
Returns the value of attribute auth_cookies.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def @auth_cookies end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def base_url @base_url end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def @cookies end |
#current_session ⇒ Object (readonly)
Returns the value of attribute current_session.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def current_session @current_session end |
#internal_adapter ⇒ Object (readonly)
Returns the value of attribute internal_adapter.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def internal_adapter @internal_adapter end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def logger @logger end |
#new_session ⇒ Object (readonly)
Returns the value of attribute new_session.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def new_session @new_session end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def @options end |
#rate_limit_config ⇒ Object (readonly)
Returns the value of attribute rate_limit_config.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def rate_limit_config @rate_limit_config end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def secret @secret end |
#session_config ⇒ Object (readonly)
Returns the value of attribute session_config.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def session_config @session_config end |
#social_providers ⇒ Object (readonly)
Returns the value of attribute social_providers.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def @social_providers end |
#trusted_origins ⇒ Object (readonly)
Returns the value of attribute trusted_origins.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def trusted_origins @trusted_origins end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
7 8 9 |
# File 'lib/better_auth/context.rb', line 7 def version @version end |
Instance Method Details
#apply_plugin_context!(attributes) ⇒ Object
78 79 80 81 82 |
# File 'lib/better_auth/context.rb', line 78 def apply_plugin_context!(attributes) normalize_context(attributes).each do |key, value| instance_variable_set("@#{key}", value) if plugin_context_attribute?(key) end end |
#create_auth_cookie(cookie_name, override_attributes = {}) ⇒ Object
66 67 68 |
# File 'lib/better_auth/context.rb', line 66 def (, override_attributes = {}) Cookies.(, .to_s, override_attributes) end |
#prepare_for_request!(request) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/better_auth/context.rb', line 103 def prepare_for_request!(request) @current_session = nil @new_session = nil @base_url = inferred_base_url(request) if .base_url.to_s.empty? @trusted_origins = current_trusted_origins(request) end |
#refresh_from_options! ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/better_auth/context.rb', line 84 def @social_providers = . @session_config = .session @rate_limit_config = .rate_limit @trusted_origins = .trusted_origins @secret = .secret end |
#reset_runtime! ⇒ Object
110 111 112 113 |
# File 'lib/better_auth/context.rb', line 110 def reset_runtime! @current_session = nil @new_session = nil end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
99 100 101 |
# File 'lib/better_auth/context.rb', line 99 def respond_to_missing?(name, include_private = false) instance_variable_defined?(:"@#{name}") || super end |
#run_in_background(task) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/better_auth/context.rb', line 57 def run_in_background(task) handler = .advanced.dig(:background_tasks, :handler) if handler.respond_to?(:call) handler.call(task) elsif task.respond_to?(:call) task.call end end |
#set_adapter(adapter) ⇒ Object
70 71 72 |
# File 'lib/better_auth/context.rb', line 70 def set_adapter(adapter) @adapter = adapter end |
#set_current_session(session) ⇒ Object
53 54 55 |
# File 'lib/better_auth/context.rb', line 53 def set_current_session(session) @current_session = session end |
#set_internal_adapter(adapter) ⇒ Object
74 75 76 |
# File 'lib/better_auth/context.rb', line 74 def set_internal_adapter(adapter) @internal_adapter = adapter end |
#set_new_session(session) ⇒ Object
49 50 51 |
# File 'lib/better_auth/context.rb', line 49 def set_new_session(session) @new_session = session end |
#trusted_origin?(url, allow_relative_paths: false) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/better_auth/context.rb', line 43 def trusted_origin?(url, allow_relative_paths: false) trusted_origins.any? do |origin| Configuration.matches_origin_pattern?(url, origin, allow_relative_paths: allow_relative_paths) end end |