module CustomFields::Types::Email::Target::ClassMethods

Public Instance Methods

apply_email_custom_field(klass, rule) click to toggle source

Add a string field

@param [ Class ] klass The class to modify @param [ Hash ] rule It contains the name of the field and if it is required or not

# File lib/custom_fields/types/email.rb, line 17
def apply_email_custom_field(klass, rule)
  name = rule['name']

  klass.field name, type: ::String, localize: rule['localized'] || false, default: rule['default']
  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) click to toggle source

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

@param [ Object ] instance An instance of the class enhanced by the custom_fields @param [ String ] name The name of the string custom field

@return [ Hash ] field name => raw value

# File lib/custom_fields/types/email.rb, line 35
def email_attribute_get(instance, name)
  default_attribute_get(instance, name)
end
email_attribute_set(instance, name, attributes) click to toggle source

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

@param [ Object ] instance An instance of the class enhanced by the custom_fields @param [ String ] name The name of the string custom field @param [ Hash ] attributes The attributes used to fetch the values

# File lib/custom_fields/types/email.rb, line 46
def email_attribute_set(instance, name, attributes)
  default_attribute_set(instance, name, attributes)
end