Sha256: 3e3423de664d8ed6521919bab8f755af9847736a5b3201a7fd738d8ce2e6f502

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'active_support/concern'

require 'frenetic/hypermedia_link_set'

class Frenetic
  module HalLinked
    extend ActiveSupport::Concern

    def links
      @params['_links']
    end

    def member_url( params = {} )
      resource = @resource_type || self.class.to_s.demodulize.underscore
      link = links[resource] || links['self'] or raise HypermediaError, %Q{No Hypermedia GET Url found for the resource "#{resource}"}
      HypermediaLinkSet.new( link ).href params
    end

    module ClassMethods
      def links
        api.description['_links']
      end

      def member_url( params = {} )
        link = links[namespace] or raise HypermediaError, %Q{No Hypermedia GET Url found for the resource "#{namespace}"}
        HypermediaLinkSet.new( link ).href params
      end

      def collection_url
        link = links[namespace.pluralize] or raise HypermediaError, %Q{No Hypermedia GET Url found for the resource "#{namespace.pluralize}"}
        HypermediaLinkSet.new( link ).href
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frenetic-1.0.0.alpha.1 lib/frenetic/concerns/hal_linked.rb