Sha256: 302b0696f752c3e844653fa327554f299add97bac7476d911f1c4fc06ad0d3d8

Contents?: true

Size: 731 Bytes

Versions: 1

Compression:

Stored size: 731 Bytes

Contents

module Georgia
  class Link < ActiveRecord::Base

    include Concerns::Contentable

    belongs_to :menu, class_name: Georgia::Menu, touch: true

    # acts_as_list scope: :menu
    has_ancestry orphan_strategy: :adopt

    scope :ordered, -> { order('position ASC') }

    before_validation :ensure_forward_slash, on: :create

    def ensure_forward_slash
      self.contents.each do |content|
        content.text.insert(0, '/') unless content.text =~ Regexp.new('(^/)|(^http)')
      end
    end

    # returns only the last part of the url
    def slug
      @slug ||= text.match(/([\w-]*)$/)[0]
    end

    def url
      @url ||= self.text
    end

    def self.policy_class
      Georgia::NavigationPolicy
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
georgia-0.8.0 app/models/georgia/link.rb