Sha256: 0ce48db33a29d1d6ef55d2e8cc4ed758ce05b49af5721d5696766722a4bbe660

Contents?: true

Size: 985 Bytes

Versions: 8

Compression:

Stored size: 985 Bytes

Contents

# frozen_string_literal: true

require 'active_support/concern'

module AppStoreConnect
  module Object
    module Data
      extend ActiveSupport::Concern

      included do
        attr_reader :data

        klass = Class.new do |data|
          include Object::Attributes
          include Object::Type

          data.define_method :initialize do |**kwargs|
            instance_variable_set('@relationships', kwargs.delete(:relationships).to_h)
            instance_variable_set('@attributes', data::Attributes.new(kwargs))
          end

          def to_h
            {
              relationships: @relationships,
              attributes: attributes.to_h,
              type: type
            }
          end
        end

        const_set('Data', klass)

        def to_h
          {
            data: data.to_h
          }
        end
      end

      class_methods do
        def data(&block)
          self::Data.class_eval(&block)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
app_store_connect-0.15.0 lib/app_store_connect/object/data.rb
app_store_connect-0.14.0 lib/app_store_connect/object/data.rb
app_store_connect-0.13.0 lib/app_store_connect/object/data.rb
app_store_connect-0.12.2 lib/app_store_connect/object/data.rb
app_store_connect-0.12.1 lib/app_store_connect/object/data.rb
app_store_connect-0.12.0 lib/app_store_connect/object/data.rb
app_store_connect-0.11.0 lib/app_store_connect/object/data.rb
app_store_connect-0.10.0 lib/app_store_connect/object/data.rb