Sha256: 50ce79ea8b1815911b445e3d3ff613bd8468c738756b6b19e38930b5a7262390

Contents?: true

Size: 1.13 KB

Versions: 29

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module FmRest
  module Spyke
    module Model
      module URI
        extend ::ActiveSupport::Concern

        included do
          # Make the layout setting inheritable
          class_attribute :_layout, instance_predicate: false

          class << self
            protected :_layout
          end
        end

        class_methods do
          # Accessor for FM layout (user for building request URIs).
          #
          # @param layout [String] The FM layout to connect this class to
          #
          # @return [String] The current layout if manually set, or the name of
          #   the class otherwise
          #
          def layout(layout = nil)
            self._layout = layout.dup.to_s.freeze if layout
            self._layout || model_name.name
          end

          # Spyke override -- Extends `uri` to default to FM Data's URI schema
          #
          def uri(uri_template = nil)
            if @uri.nil? && uri_template.nil?
              return FmRest::V1.record_path(layout) + "(/:#{primary_key})"
            end
            super
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
fmrest-spyke-0.18.0.rc1 lib/fmrest/spyke/model/uri.rb
fmrest-spyke-0.17.1 lib/fmrest/spyke/model/uri.rb
fmrest-spyke-0.17.0 lib/fmrest/spyke/model/uri.rb
fmrest-spyke-0.17.0.rc1 lib/fmrest/spyke/model/uri.rb
fmrest-spyke-0.16.0 lib/fmrest/spyke/model/uri.rb
fmrest-spyke-0.15.2 lib/fmrest/spyke/model/uri.rb
fmrest-spyke-0.15.1 lib/fmrest/spyke/model/uri.rb
fmrest-spyke-0.15.0 lib/fmrest/spyke/model/uri.rb
fmrest-spyke-0.14.0 lib/fmrest/spyke/model/uri.rb