Class: Biometric::Create
- Inherits:
-
Object
- Object
- Biometric::Create
- Defined in:
- lib/biometric/create.rb
Overview
Create class for handling biometric Createing
Class Method Summary collapse
- .biometric_key_params(params) ⇒ Object
- .call(biometric_key_params, keyable) ⇒ Object
- .create_new_biometric_key(biometric_key_params, keyable) ⇒ Object
- .error_response(message) ⇒ Object
- .existing_biometric_key(biometric_key_params, keyable) ⇒ Object
- .success_response ⇒ Object
Class Method Details
.biometric_key_params(params) ⇒ Object
21 22 23 |
# File 'lib/biometric/create.rb', line 21 def self.biometric_key_params(params) params.require(:biometric_key).permit(:device_id, :public_key) end |
.call(biometric_key_params, keyable) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/biometric/create.rb', line 6 def self.call(biometric_key_params, keyable) existing_biometric = existing_biometric_key(biometric_key_params, keyable) if existing_biometric.present? if existing_biometric.public_key == biometric_key_params[:biometric_key][:public_key] return error_response('Biometric key for device already exists') end existing_biometric.update!(public_key: biometric_key_params[:biometric_key][:public_key]) return success_response end create_new_biometric_key(biometric_key_params(biometric_key_params), keyable) end |
.create_new_biometric_key(biometric_key_params, keyable) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/biometric/create.rb', line 29 def self.create_new_biometric_key(biometric_key_params, keyable) biometric_key = keyable.biometric_keys.new(biometric_key_params) return error_response(biometric_key.errors..join(', ')) unless biometric_key.save success_response end |
.error_response(message) ⇒ Object
40 41 42 |
# File 'lib/biometric/create.rb', line 40 def self.error_response() { success: false, error: } end |
.existing_biometric_key(biometric_key_params, keyable) ⇒ Object
25 26 27 |
# File 'lib/biometric/create.rb', line 25 def self.existing_biometric_key(biometric_key_params, keyable) keyable.biometric_keys.find_by(device_id: biometric_key_params[:biometric_key][:device_id]) end |
.success_response ⇒ Object
36 37 38 |
# File 'lib/biometric/create.rb', line 36 def self.success_response { success: true } end |