Sha256: 56f56783883b8f530d9bc2a44d3363a8227a8108b15e8c3561d3010094e7751f

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

module Sections
  #:nodoc:
  module Model
    ##
    # Model that represents a single section.
    #
    # @since  0.1
    #
    class Section < Sequel::Model
      include Zen::Model::Helper

      one_to_many :section_entries,
        :class => 'Sections::Model::SectionEntry',
        :eager => [:custom_field_values, :section_entry_status]

      many_to_many :custom_field_groups,
        :class => 'CustomFields::Model::CustomFieldGroup'

      many_to_many :category_groups,
        :class => 'Categories::Model::CategoryGroup'

      plugin :sluggable, :source => :name, :freeze => false

      ##
      # Searches for a number of sections of which the title or description
      # matches the search query.
      #
      # @example
      #  Sections::Model::Section.search('pages')
      #
      # @since  16-10-2011
      # @param  [String] query The search query.
      # @return [Mixed]
      #
      def self.search(query)
        return filter(
          search_column(:name, query) | search_column(:description, query)
        )
      end

      ##
      # Specifies all validation rules for each section.
      #
      # @since  0.1
      #
      def validate
        validates_presence([
          :name,
          :comment_allow,
          :comment_require_account,
          :comment_moderate,
          :comment_format
        ])

        validates_max_length(255, [:name, :slug])

        validates_type(
          TrueClass,
          [:comment_allow, :comment_require_account, :comment_moderate]
        )

        validates_unique(:slug)
      end
    end # Section
  end # Model
end # Sections

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zen-0.3 lib/zen/package/sections/lib/sections/model/section.rb
zen-0.3b1 lib/zen/package/sections/lib/sections/model/section.rb
zen-0.3b lib/zen/package/sections/lib/sections/model/section.rb