Sha256: f885b1d9757e3f5e01491a8835c6f24d7df0a9dcc3dd2207bcca025f9efeefa5

Contents?: true

Size: 809 Bytes

Versions: 14

Compression:

Stored size: 809 Bytes

Contents

module JsonApiClient
  module Helpers
    module Linkable
      extend ActiveSupport::Concern

      included do
        attr_accessor :links,
                      :linked_data

        initializer do |obj, params|
          if params && links = params.delete("links")
            obj.links = links
          end
        end
      end

      def method_missing(method, *args)
        return super unless has_link?(method)

        linked_data.data_for(method, links[method.to_s])
      end

      def respond_to?(symbol, include_all = false)
        return true if has_link?(symbol)
        super
      end

      private

      def has_link?(symbol)
        links && 
          links.has_key?(symbol.to_s) &&
          linked_data && 
          linked_data.has_link?(symbol.to_s)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
json_api_client-0.9.6 lib/json_api_client/helpers/linkable.rb
json_api_client-0.9.5 lib/json_api_client/helpers/linkable.rb
json_api_client-0.9.4 lib/json_api_client/helpers/linkable.rb
json_api_client-0.9.3 lib/json_api_client/helpers/linkable.rb
json_api_client-0.9.2 lib/json_api_client/helpers/linkable.rb
json_api_client-0.9.0 lib/json_api_client/helpers/linkable.rb
json_api_client-0.8.1 lib/json_api_client/helpers/linkable.rb
json_api_client-0.8.0 lib/json_api_client/helpers/linkable.rb
json_api_client-0.7.1 lib/json_api_client/helpers/linkable.rb
json_api_client-0.7.0 lib/json_api_client/helpers/linkable.rb
json_api_client-0.6.0 lib/json_api_client/helpers/linkable.rb
json_api_client-0.5.1 lib/json_api_client/helpers/linkable.rb
json_api_client-0.5.0 lib/json_api_client/helpers/linkable.rb
json_api_client-0.4.0 lib/json_api_client/helpers/linkable.rb