Module: CustomFields::Types::Float::Target::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

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



17
18
19
20
21
# File 'lib/custom_fields/types/float.rb', line 17

def apply_float_custom_field(klass, rule)
  klass.field rule['name'], type: ::Float, localize: rule['localized'] || false, default: rule['default']
  klass.validates_presence_of rule['name'] if rule['required']
  klass.validates rule['name'], numericality: true, if: ->(_x) { rule['required'] }
end

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



31
32
33
# File 'lib/custom_fields/types/float.rb', line 31

def float_attribute_get(instance, name)
  default_attribute_get(instance, name)
end

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



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

def float_attribute_set(instance, name, attributes)
  default_attribute_set(instance, name, attributes)
end