Sha256: 96c06711d634f6f4b535d4e4c42a0db9b0453d07645ee54c65aa9e4532ace8ee

Contents?: true

Size: 639 Bytes

Versions: 9

Compression:

Stored size: 639 Bytes

Contents

module Acfs::Model

  # Provide methods for generation URLs for resources.
  #
  # Example
  #   class User
  #     service AccountService # With base URL `http://acc.svr`
  #   end
  #   User.url             #=> "http://acc.svr/users"
  #   User.url(5)          #=> "http://acc.svr/users/5"
  #
  module Locatable
    extend ActiveSupport::Concern

    module ClassMethods

      # Return URL for this resource.
      #
      def url(suffix = nil)
        service.url_for(self, suffix: suffix)
      end
    end

    def url
      return nil if id.nil?
      self.class.service.url_for self, suffix: read_attribute(:id)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
acfs-0.16.0 lib/acfs/model/locatable.rb
acfs-0.15.0 lib/acfs/model/locatable.rb
acfs-0.14.0 lib/acfs/model/locatable.rb
acfs-0.13.0 lib/acfs/model/locatable.rb
acfs-0.12.0 lib/acfs/model/locatable.rb
acfs-0.11.0 lib/acfs/model/locatable.rb
acfs-0.10.0 lib/acfs/model/locatable.rb
acfs-0.9.0 lib/acfs/model/locatable.rb
acfs-0.8.0 lib/acfs/model/locatable.rb