Class: CustomFields::Model::CustomFieldType

Inherits:
Sequel::Model show all
Includes:
Zen::Model::Helper
Defined in:
lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb

Overview

Model for managing custom field types.

Since:

Constant Summary

Constant Summary

Constants included from Zen::Model::Helper

Zen::Model::Helper::NoRegexpSupport

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Zen::Model::Helper

included

Methods inherited from Sequel::Model

pk_hash

Class Method Details

+ (Mixed) search(query)

Searches for a set of custom field types.

Parameters:

  • query (String)

    The search query.

Returns:

  • (Mixed)

Since:

  • 16-10-2011



22
23
24
25
# File 'lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb', line 22

def self.search(query)
  return filter(search_column(:custom_field_types__name, query)) \
    .eager(:custom_field_method)
end

+ (Hash) type_hash

Returns a hash where the keys are the IDs of all custom field types and the values the full language strings based on the value of the column "language_string".

Returns:

  • (Hash)

Since:

  • 0.2.8



35
36
37
38
39
40
41
42
43
# File 'lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb', line 35

def self.type_hash
  rows = {}

  CustomFieldType.select(:id, :language_string).each do |row|
    rows[row.id] = lang(row.language_string)
  end

  return rows
end

Instance Method Details

- (Object) validate

Validates the model before inserting/updating the database record.

Since:

  • 0.2.8



50
51
52
53
54
55
56
57
# File 'lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb', line 50

def validate
  validates_presence([:name, :language_string, :custom_field_method_id])
  validates_integer(:custom_field_method_id)
  validates_type(TrueClass, [:serialize, :allow_markup])
  validates_format(/^[a-zA-Z\-_0-9\s]*$/, [:html_class])

  validates_max_length(255, [:name, :language_string, :html_class])
end