Sha256: ce994883d60571ff1e9a89700641e974cf6f3b0e6e902db85d2163fc194f3329

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

#:nodoc:
module Categories
  #:nodoc:
  module Models
    ##
    # Model that represents a single category. This model has the following relations:
    #
    # * category groups (one to one)
    # * self (many to one)
    #
    # This model uses the following plugins:
    #
    # * sluggable (source: "name")
    #
    # When creating or saving a category the fields "name" and "slug" are required.
    # The latter is only needed when saving an existing category as a slug will be
    # generated whenever the field is empty. It's also important to remember
    # that slugs have to be unique. For more info see the validate() method.
    #
    # @author Yorick Peterse
    # @since  0.1
    #
    class Category < Sequel::Model
      many_to_one :category_group , :class => "Categories::Models::CategoryGroup"
      many_to_one :parent         , :class => self
      
      plugin :sluggable, :source => :name, :frozen => false
      
      ##
      # Validation rules for our model.
      #
      # @author Yorick Peterse
      # @since  0.1
      #
      def validate
        validates_presence    :name
        validates_max_length  255, [:name, :slug]
        validates_unique      :slug
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zen-0.2.4.1 lib/zen/package/categories/lib/categories/model/category.rb
zen-0.2.4 lib/zen/package/categories/lib/categories/model/category.rb
zen-0.2.3 lib/zen/package/categories/lib/categories/model/category.rb
zen-0.2 lib/zen/package/categories/lib/categories/model/category.rb