Class: BetterAuth::Rails::OptionBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ OptionBuilder

Returns a new instance of OptionBuilder.



6
7
8
# File 'lib/better_auth/rails/option_builder.rb', line 6

def initialize(values = {})
  @values = deep_dup(symbolize_keys(values || {}))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/better_auth/rails/option_builder.rb', line 14

def method_missing(name, *args, &block)
  method_name = name.to_s
  if method_name.end_with?("=")
    key = method_name.delete_suffix("=").to_sym
    @values[key] = args.first
  elsif block
    key = method_name.to_sym
    nested = self.class.new(@values[key].is_a?(Hash) ? @values[key] : {})
    yield nested
    @values[key] = nested.to_h
  elsif args.empty?
    @values[method_name.to_sym]
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/better_auth/rails/option_builder.rb', line 31

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

#to_hObject



10
11
12
# File 'lib/better_auth/rails/option_builder.rb', line 10

def to_h
  deep_dup(@values)
end