Module: CustomFields::Types::Boolean::Target::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#apply_boolean_custom_field(klass, rule) ⇒ Object

Adds a boolean field. It can not be required.

Parameters:

  • klass (Class)

    The class to modify

  • rule (Hash)

    It contains the name of the field.



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

def apply_boolean_custom_field(klass, rule)
  klass.field rule['name'], type: 'Boolean', localize: rule['localized'] || false,
                            default: rule['default'].nil? ? false : rule['default']
end

#boolean_attribute_get(instance, name) ⇒ Hash

Build a hash storing the boolean value (true / false) for a boolean custom field of an instance.

Parameters:

  • instance (Object)

    An instance of the class enhanced by the custom_fields

  • name (String)

    The name of the boolean custom field

Returns:

  • (Hash)

    field name => true / false



30
31
32
# File 'lib/custom_fields/types/boolean.rb', line 30

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

#boolean_attribute_set(instance, name, attributes) ⇒ Object

Set the value for the instance and the boolean 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 boolean custom field

  • attributes (Hash)

    The attributes used to fetch the values



41
42
43
# File 'lib/custom_fields/types/boolean.rb', line 41

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