Class: BetterAuth::PluginRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/better_auth/plugin_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ PluginRegistry

Returns a new instance of PluginRegistry.



7
8
9
10
# File 'lib/better_auth/plugin_registry.rb', line 7

def initialize(context)
  @context = context
  @plugins = context.options.plugins
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/better_auth/plugin_registry.rb', line 5

def context
  @context
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



5
6
7
# File 'lib/better_auth/plugin_registry.rb', line 5

def plugins
  @plugins
end

Instance Method Details

#endpointsObject



27
28
29
30
31
# File 'lib/better_auth/plugin_registry.rb', line 27

def endpoints
  plugins.each_with_object({}) do |plugin, result|
    result.merge!(plugin.endpoints)
  end
end

#error_codes(base) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/better_auth/plugin_registry.rb', line 33

def error_codes(base)
  plugins.each_with_object(base.dup) do |plugin, codes|
    plugin.error_codes.each do |key, value|
      codes[key.to_s.upcase] = value
    end
  end
end

#run_init!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/better_auth/plugin_registry.rb', line 12

def run_init!
  plugins.each do |plugin|
    next unless plugin.init

    result = plugin.init.call(context)
    next unless result.is_a?(Hash)

    apply_options(plugin, result[:options] || result["options"])
    PluginContext.new(context, plugin).apply!(result[:context] || result["context"])
  end

  context.refresh_from_options!
  context.set_internal_adapter(Adapters::InternalAdapter.new(context.adapter, context.options))
end