Sha256: 46e17518a0042ee8811a8585276f1e0c458c0cc28724361dd40f122abc2ff4b7

Contents?: true

Size: 1.32 KB

Versions: 71

Compression:

Stored size: 1.32 KB

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 class of resource. Given suffix will be appended.
      #
      # @example
      #   User.url    # => "http://users.srv.org/users"
      #   User.url(5) # => "http://users.srv.org/users/5"
      #
      # @param [ String ] suffix Suffix to append to URL.
      # @return [ String ] Generated URL.
      # @see Acfs::Service#url_for Delegates to Service#url_for with `suffix` option.
      #
      def url(suffix = nil)
        service.url_for(self, suffix: suffix)
      end
    end

    # Return URL for this resource. Resource if will be appended
    # as suffix if present.
    #
    # @example
    #   user.new.url # => "http://users.srv.org/users"
    #
    #   user = User.find 5
    #   Acfs.run
    #   user.url # => "http://users.srv.org/users/5"
    #
    # @return [ String ] Generated URL.
    # @see ClassMethods#url
    #
    def url
      return nil if id.nil?
      self.class.service.url_for self, suffix: read_attribute(:id)
    end
  end
end

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
acfs-0.30.0.1.b260 lib/acfs/model/locatable.rb
acfs-0.30.0 lib/acfs/model/locatable.rb
acfs-0.29.1.1.b259 lib/acfs/model/locatable.rb
acfs-0.29.1.1.b257 lib/acfs/model/locatable.rb
acfs-0.29.1 lib/acfs/model/locatable.rb
acfs-0.29.0.1.b256 lib/acfs/model/locatable.rb
acfs-0.29.0.1.b254 lib/acfs/model/locatable.rb
acfs-0.29.0 lib/acfs/model/locatable.rb
acfs-0.28.0.1.b253 lib/acfs/model/locatable.rb
acfs-0.28.0.1.b249 lib/acfs/model/locatable.rb
acfs-0.28.0 lib/acfs/model/locatable.rb
acfs-0.27.0.1.b248 lib/acfs/model/locatable.rb
acfs-0.27.0.1.b244 lib/acfs/model/locatable.rb
acfs-0.27.0 lib/acfs/model/locatable.rb
acfs-0.26.0.1.b243 lib/acfs/model/locatable.rb
acfs-0.26.0.1.b242 lib/acfs/model/locatable.rb
acfs-0.26.0 lib/acfs/model/locatable.rb
acfs-0.25.0.1.b232 lib/acfs/model/locatable.rb
acfs-0.25.0.1.b229 lib/acfs/model/locatable.rb
acfs-0.25.0.1.b228 lib/acfs/model/locatable.rb