Sha256: 2f6f916442ae5c2179523b4f9a7b2e7e04f0b05ef3a34bc3e6df982a3b2c789e

Contents?: true

Size: 895 Bytes

Versions: 35

Compression:

Stored size: 895 Bytes

Contents

module JsonApiClient
  module Linking
    class TopLevelLinks

      attr_reader :links, :record_class

      def initialize(record_class, links)
        @links = links
        @record_class = record_class
      end

      def respond_to_missing?(method, include_private = false)
        links.has_key?(method.to_s) || super
      end

      def method_missing(method, *args)
        if respond_to_missing?(method)
          fetch_link(method)
        else
          super
        end
      end

      def link_url_for(link_name)
        link_definition = links.fetch(link_name.to_s)
        if link_definition.is_a?(Hash)
          link_definition["href"]
        else
          link_definition
        end
      end

      def fetch_link(link_name)
        return unless respond_to_missing?(link_name)
        record_class.requestor.linked(link_url_for(link_name))
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
json_api_client-1.23.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.22.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.21.1 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.21.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.20.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.19.0 lib/json_api_client/linking/top_level_links.rb
carwow-json_api_client-1.19.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.18.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.17.1 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.17.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.16.1 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.16.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.15.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.14.1 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.14.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.13.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.12.2 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.12.1 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.12.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.11.0 lib/json_api_client/linking/top_level_links.rb