Sha256: 9cdc23bdfbfcfdfce654be53e209ee1a33abcfaa61a907309ca1804f6ad06b7b

Contents?: true

Size: 984 Bytes

Versions: 17

Compression:

Stored size: 984 Bytes

Contents

module PushType
  class Taxonomy < ActiveRecord::Base

    include PushType::Templatable
    include PushType::Unexposable

    acts_as_tree name_column: 'slug', order: 'sort_order', dependent: :destroy

    validates :title, presence: true, uniqueness: { scope: :parent_id }
    validates :slug,  presence: true, uniqueness: { scope: :parent_id }

    class << self
      def title
        @title ||= name.underscore.humanize.pluralize
      end

      def base_slug(*args)
        if args.present?
          @base_slug = args.first
        else
          ( @base_slug || name ).to_s.underscore
        end
      end
    end

    def base_slug
      self.class.base_slug
    end

    def permalink(with_base_sug = false)
      @permalink ||= self_and_ancestors.map(&:slug).reverse
      (with_base_sug ? @permalink.unshift(base_slug) : @permalink).join('/')
    end

    def full_permalink
      permalink(true)
    end

    def exposed?
      self.class.exposed?
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
push_type_core-0.7.0 app/models/push_type/taxonomy.rb
push_type_core-0.7.0.beta.1 app/models/push_type/taxonomy.rb
push_type_core-0.6.0 app/models/push_type/taxonomy.rb
push_type_core-0.6.0.beta.4 app/models/push_type/taxonomy.rb
push_type_core-0.6.0.beta.3 app/models/push_type/taxonomy.rb
push_type_core-0.6.0.beta.2 app/models/push_type/taxonomy.rb
push_type_core-0.6.0.beta.1 app/models/push_type/taxonomy.rb
push_type_core-0.5.3 app/models/push_type/taxonomy.rb
push_type_core-0.5.2 app/models/push_type/taxonomy.rb
push_type_core-0.5.1 app/models/push_type/taxonomy.rb
push_type_core-0.5.0 app/models/push_type/taxonomy.rb
push_type_core-0.5.0.alpha.5 app/models/push_type/taxonomy.rb
push_type_core-0.5.0.alpha.4 app/models/push_type/taxonomy.rb
push_type_core-0.5.0.alpha.3 app/models/push_type/taxonomy.rb
push_type_core-0.5.0.alpha.2 app/models/push_type/taxonomy.rb
push_type_core-0.5.0.alpha.1 app/models/push_type/taxonomy.rb
push_type_core-0.4.0 app/models/push_type/taxonomy.rb