Sha256: d1828abd813e7a071801e7f8282d906f49a819b4c2f76e1206e399c9c8aba9e5

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

#:nodoc:
module Menus
  #:nodoc:
  module Models
    ##
    # Model used for managing groups of menu items. This model uses the following
    # Sequel plugins:
    #
    # * sluggable
    #
    # @author Yorick Peterse
    # @since  0.2a
    #
    class Menu < Sequel::Model
      plugin :sluggable, :source => :name, :freeze => false

      # Define our relations
      one_to_many :menu_items, :class => "Menus::Models::MenuItem"

      ##
      # Specifies all validates rules used when creating or updating a menu.
      # A slug will be generated when a menu is first created but after that they are
      # required to ensure that they don't collide with existing slugs.
      #
      # @author Yorick Peterse
      # @since  0.2a
      #
      def validate
        validates_presence :name
        validates_presence :slug unless new? 
        validates_unique   :slug
      
        # Prevent people from entering random crap for class and ID names
        validates_format(/^[a-zA-Z\-_0-9]*/, [:css_class, :css_id])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zen-0.2.4.1 lib/zen/package/menus/lib/menus/model/menu.rb
zen-0.2.4 lib/zen/package/menus/lib/menus/model/menu.rb
zen-0.2.3 lib/zen/package/menus/lib/menus/model/menu.rb
zen-0.2 lib/zen/package/menus/lib/menus/model/menu.rb