Module: CustomFields::Types::Email::Target::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#apply_email_custom_field(klass, rule) ⇒ Object

Add a string field

Parameters:

  • klass (Class)

    The class to modify

  • rule (Hash)

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



20
21
22
23
24
25
26
27
# File 'lib/custom_fields/types/email.rb', line 20

def apply_email_custom_field(klass, rule)
  name = rule['name']

  klass.field name, type: ::String, localize: rule['localized'] || false
  klass.validates_presence_of name if rule['required']
  klass.validates_format_of name, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, allow_blank: !rule['required']
  klass.validates_uniqueness_of rule['name'], scope: :_type if rule['unique']
end

#email_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



37
38
39
# File 'lib/custom_fields/types/email.rb', line 37

def email_attribute_get(instance, name)
  self.default_attribute_get(instance, name)
end

#email_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



48
49
50
# File 'lib/custom_fields/types/email.rb', line 48

def email_attribute_set(instance, name, attributes)
  self.default_attribute_set(instance, name, attributes)
end