Sha256: 029df4d6a2761e224537f3f974378f05a1c299d9418c4e3b6bbf3e52c2411a83

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

require 'active_support/concern'

module Cardboard
  module UrlConcern
    extend ActiveSupport::Concern

    included do
      has_one :url_object, class_name: "Cardboard::Url", :as => :urlable, :autosave => true, :dependent => :destroy
   
      def url_object_with_auto_build
        build_url_object unless url_object_without_auto_build
        url_object_without_auto_build #to continue the association chain
      end
      alias_method_chain :url_object, :auto_build

      accepts_nested_attributes_for :url_object

      delegate :slug, :slug=,
               :path, :path=, 
               :meta_tags, :meta_tags=,
               :using_slug_backup?,  
               to: :url_object, allow_nil: true
    end

    def url
      url_object.to_s
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cardboard_cms-0.3.1 lib/cardboard/concerns/url_concern.rb