Class: Unmagic::Passkeys::Holder::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/unmagic/passkeys/holder.rb

Overview

Configuration object yielded by has_passkeys when a block is given. Allows setting custom association options and ceremony option blocks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Config

Returns a new instance of Config.



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/unmagic/passkeys/holder.rb', line 75

def initialize(**options)
  @association_name = options.delete(:association_name) || :passkeys
  @dependent = options.delete(:dependent) || :destroy

  if creation_opts = extract_options_for(Unmagic::Passkeys::WebAuthn::PublicKeyCredential::CreationOptions, options)
    @registration_options = options_to_proc(creation_opts)
  end

  if request_opts = extract_options_for(Unmagic::Passkeys::WebAuthn::PublicKeyCredential::RequestOptions, options)
    @authentication_options = options_to_proc(request_opts)
  end
end

Instance Attribute Details

#association_nameObject

Returns the value of attribute association_name.



73
74
75
# File 'lib/unmagic/passkeys/holder.rb', line 73

def association_name
  @association_name
end

#dependentObject

Returns the value of attribute dependent.



73
74
75
# File 'lib/unmagic/passkeys/holder.rb', line 73

def dependent
  @dependent
end

Instance Method Details

#authentication_options(&block) ⇒ Object

Sets a block to evaluate in the holder’s context to produce additional authentication options.

config.authentication_options { { user_verification: "required" } }


91
92
93
# File 'lib/unmagic/passkeys/holder.rb', line 91

def authentication_options(&block)
  @authentication_options = block
end

#evaluate_authentication_options(record) ⇒ Object

Evaluates the request options block (if any) in the context of the given record. Called internally by the passkey_authentication_options method defined on the holder.



104
105
106
107
108
109
110
# File 'lib/unmagic/passkeys/holder.rb', line 104

def evaluate_authentication_options(record)
  if @authentication_options
    record.instance_exec(&@authentication_options)
  else
    {}
  end
end

#evaluate_registration_options(record) ⇒ Object

Evaluates the creation options block (if any) in the context of the given record. Called internally by the passkey_registration_options method defined on the holder.



114
115
116
117
118
119
120
# File 'lib/unmagic/passkeys/holder.rb', line 114

def evaluate_registration_options(record)
  if @registration_options
    record.instance_exec(&@registration_options)
  else
    {}
  end
end

#registration_options(&block) ⇒ Object

Sets a block to evaluate in the holder’s context to produce additional creation options.

config.registration_options { { name: email, display_name: name } }


98
99
100
# File 'lib/unmagic/passkeys/holder.rb', line 98

def registration_options(&block)
  @registration_options = block
end