Sha256: b2a450963fb55d4c1cf55176971e3ab7fa19419d6cd9c33a6d52d22fb2861d23

Contents?: true

Size: 926 Bytes

Versions: 7

Compression:

Stored size: 926 Bytes

Contents

##
# Identifier
#
# Some unique keys which can be used for routing
# and APIs
module Outpost
  module Model
    module Identifier
      extend ActiveSupport::Concern

      OBJ_KEY_SEPARATOR = "-"

      module ClassMethods
        def content_key
          self.name.tableize.singularize
        end

        def obj_key(id)
          [self.content_key, id || "new"].join(OBJ_KEY_SEPARATOR)
        end

        def new_obj_key
          obj_key(nil)
        end

        # Wrappers for ActiveModel::Naming
        # NewsStory => news_stories
        def route_key
          ActiveModel::Naming.route_key(self)
        end

        # NewsStory => news_story
        def singular_route_key
          ActiveModel::Naming.singular_route_key(self)
        end
      end

      # Default obj_key pattern
      def obj_key
        @obj_key ||= self.class.obj_key(self.id)
      end
    end # Identifier
  end # Model
end # Outpost

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
outpost-cms-0.1.4 lib/outpost/model/identifier.rb
outpost-cms-0.1.3 lib/outpost/model/identifier.rb
outpost-cms-0.1.2 lib/outpost/model/identifier.rb
outpost-cms-0.1.1 lib/outpost/model/identifier.rb
outpost-cms-0.1.0 lib/outpost/model/identifier.rb
outpost-cms-0.0.5 lib/outpost/model/identifier.rb
outpost-cms-0.0.4 lib/outpost/model/identifier.rb