Module: Motor::BuildSchema::AdjustDeviseModelSchema

Defined in:
lib/motor/build_schema/adjust_devise_model_schema.rb

Constant Summary collapse

HIDDEN_COLUMNS =
%w[
  encrypted_password
  reset_password_token
  confirmation_token
].freeze
READ_ONLY_COLUMNS =
%w[
  reset_password_sent_at
  remember_created_at
  sign_in_count
  current_sign_in_at
  last_sign_in_at
  current_sign_in_ip
  last_sign_in_ip
  confirmed_at
  confirmation_sent_at
].freeze

Class Method Summary collapse

Class Method Details

.add_password_column!(columns) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/motor/build_schema/adjust_devise_model_schema.rb', line 47

def add_password_column!(columns)
  columns << {
    name: 'password',
    display_name: I18n.t('motor.password'),
    column_type: 'string',
    access_type: 'write_only',
    default_value: nil,
    validators: [],
    virtual: true
  }
end

.call(schema, devise_modules) ⇒ Object


26
27
28
29
30
31
# File 'lib/motor/build_schema/adjust_devise_model_schema.rb', line 26

def call(schema, devise_modules)
  modify_column_access_types!(schema[:columns])
  add_password_column!(schema[:columns]) if devise_modules.include?(:database_authenticatable)

  schema
end

.modify_column_access_types!(columns) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/motor/build_schema/adjust_devise_model_schema.rb', line 33

def modify_column_access_types!(columns)
  columns.each do |column|
    column[:access_type] =
      case column[:name]
      when *HIDDEN_COLUMNS
        ColumnAccessTypes::HIDDEN
      when *READ_ONLY_COLUMNS
        ColumnAccessTypes::READ_ONLY
      else
        column[:access_type]
      end
  end
end