Sha256: 93246c1c1d622fd98be1af10f46bba857ce6fc3652b9966cc3ea21b1685ceb76

Contents?: true

Size: 650 Bytes

Versions: 9

Compression:

Stored size: 650 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
    attr_accessible :parent_id, :menu_id

    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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
georgia-0.7.8 app/models/georgia/link.rb
georgia-0.7.7 app/models/georgia/link.rb
georgia-0.7.6 app/models/georgia/link.rb
georgia-0.7.5 app/models/georgia/link.rb
georgia-0.7.4 app/models/georgia/link.rb
georgia-0.7.3 app/models/georgia/link.rb
georgia-0.7.2 app/models/georgia/link.rb
georgia-0.7.1 app/models/georgia/link.rb
georgia-0.7.0 app/models/georgia/link.rb