Class: CustomFields::Model::CustomFieldValue

Inherits:
Sequel::Model show all
Defined in:
lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb

Overview

Model that represents a single custom field value.

Since:

Instance Method Summary (collapse)

Methods inherited from Sequel::Model

pk_hash

Instance Method Details

- (String) html

Retrieves the value of the custom field and converts it to the output based on the markup engine specified in the custom field.

Returns:

  • (String)

Since:

  • 0.3



55
56
57
# File 'lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb', line 55

def html
  return ::Zen::Markup.convert(custom_field.format, value)
end

- (Mixed) value

Retrieves the value and optionally unserializes it.

Returns:

  • (Mixed)

Since:

  • 0.2.8



37
38
39
40
41
42
43
44
45
46
# File 'lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb', line 37

def value
  val  = super
  type = custom_field.custom_field_type

  if !type.nil? and type.serialize == true
    val = Marshal.load(val.unpack('m')[0]) rescue Marshal.load(val)
  end

  return val
end

- (Object) value=(val)

Sets the value and serializes it based on the field type.

Parameters:

  • value (Mixed)

    The value to store.

Since:

  • 0.2.8



21
22
23
24
25
26
27
28
29
# File 'lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb', line 21

def value=(val)
  type = custom_field.custom_field_type

  if !type.nil? and type.serialize == true
    val = [Marshal.dump(val)].pack('m')
  end

  super(val)
end