Sha256: c2cf73002ae719e59aee1c4c749a2ec7c759e8bbf49401385f6f259d9969193c

Contents?: true

Size: 842 Bytes

Versions: 3

Compression:

Stored size: 842 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)
        record_class.requestor.linked(link_url_for(link_name))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json_api_client-1.2.0 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.1.1 lib/json_api_client/linking/top_level_links.rb
json_api_client-1.1.0 lib/json_api_client/linking/top_level_links.rb