Sha256: 27e8ea3d99b47590acc73f4d832551bb1154c9d2bf85ca1ad61fcd67c1dd771d

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

#:nodoc:
module Menus
  #:nodoc:
  module Model
    ##
    # 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::Model::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 # Menu
  end # Model
end # Menus

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zen-0.2.7 lib/zen/package/menus/lib/menus/model/menu.rb
zen-0.2.6.1 lib/zen/package/menus/lib/menus/model/menu.rb
zen-0.2.6 lib/zen/package/menus/lib/menus/model/menu.rb