Module: CustomFields::Types::Password::Target::ClassMethods

Defined in:
lib/custom_fields/types/password.rb

Instance Method Summary collapse

Instance Method Details

#apply_password_custom_field(klass, rule) ⇒ Object

Add a password field

Parameters:

  • klass (Class)

    The class to modify

  • rule (Hash)

    It contains the name of the field and if it is required or not



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/custom_fields/types/password.rb', line 21

def apply_password_custom_field(klass, rule)
  label, name = rule['label'], rule['name']

  klass.field :"#{name}_hash"

  klass.send(:define_method, name.to_sym) { '' }
  klass.send(:define_method, :"#{name}=") { |value| _encrypt_password(name, value) }
  klass.send(:define_method, :"#{name}_confirmation") { '' }
  klass.send(:define_method, :"#{name}_confirmation=") { |value| _set_confirmation_password(name, value) }

  klass.validate { _check_password(label, name) }
end

#password_attribute_get(instance, name) ⇒ Hash

Build a hash storing the raw value for a string custom field of an instance.

Parameters:

  • instance (Object)

    An instance of the class enhanced by the custom_fields

  • name (String)

    The name of the string custom field

Returns:

  • (Hash)

    field name => raw value



42
43
44
# File 'lib/custom_fields/types/password.rb', line 42

def password_attribute_get(instance, name)
  {}
end

#password_attribute_set(instance, name, attributes) ⇒ Object

Set the value for the instance and the string field specified by the 2 params.

Parameters:

  • instance (Object)

    An instance of the class enhanced by the custom_fields

  • name (String)

    The name of the string custom field

  • attributes (Hash)

    The attributes used to fetch the values



53
54
55
# File 'lib/custom_fields/types/password.rb', line 53

def password_attribute_set(instance, name, attributes)
  instance._encrypt_password(name, attributes[name])
end