Sha256: c76c404e75e233eca76762df1f8146482ad144d1f239cc350761a4479deeab42

Contents?: true

Size: 660 Bytes

Versions: 2

Compression:

Stored size: 660 Bytes

Contents

module JsonApiClient
  module Relationships
    class Relations
      include Helpers::DynamicAttributes

      def initialize(relations)
        self.attributes = relations
      end

      def present?
        attributes.present?
      end

      def serializable_hash
        Hash[attributes.map do |k, v|
          [k, v.slice("data")]
        end]
      end

      protected

      def set_attribute(name, value)
        attributes[name] = case value
        when JsonApiClient::Resource
          {data: value.as_relation}
        when Array
          {data: value.map(&:as_relation)}
        else
          value
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json_api_client-1.0.0.beta5 lib/json_api_client/relationships/relations.rb
json_api_client-1.0.0.beta4 lib/json_api_client/relationships/relations.rb