Class: Menus::Model::MenuItem

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

Overview

Model used for managing individual menu items in a group.

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 menu items.

Parameters:

  • query (String)

    The search query.

Returns:

  • (Mixed)

Since:

  • 16-10-2011



24
25
26
27
28
29
30
# File 'lib/zen/package/menus/lib/menus/model/menu_item.rb', line 24

def self.search(query)
  return filter(
    search_column(:name, query) |
    search_column(:html_class, query) |
    search_column(:html_id, query)
  )
end

Instance Method Details

- (Object) parent_id=(parent_id)

Sets the ID of the parent navigation item but only if it's not empty and not the same as the current ID.

Parameters:

  • parent_id (Fixnum)

    The ID of the parent navigation item.

Since:

  • 0.3



53
54
55
56
57
58
# File 'lib/zen/package/menus/lib/menus/model/menu_item.rb', line 53

def parent_id=(parent_id)
  if !(parent_id.respond_to?(:empty?) and !parent_id.empty?) \
  and parent_id != self.id
    super(parent_id)
  end
end

- (Object) validate

Specifies all validation rules that will be used when creating or updating a menu item.

Since:

  • 0.2a



38
39
40
41
42
43
44
# File 'lib/zen/package/menus/lib/menus/model/menu_item.rb', line 38

def validate
  validates_presence([:name, :url])
  validates_max_length(255, [:name, :url, :html_class, :html_id])
  validates_integer([:sort_order, :parent_id])
  validates_format(/^[a-zA-Z\-_0-9\s]*$/, :html_class)
  validates_format(/^[a-zA-Z\-_0-9]*$/  , :html_id)
end