Sha256: 09e0cdaa955a3f4d96b64c1dd9931cc93d0cad90dff8097a477651af285fd2cc

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

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
          include Object::Id

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

          def to_h
            props = {
              relationships: @relationships,
              attributes: attributes.to_h,
              type: type
            }
            props[:id] = @id if id?
            props.reject { |_k, v| v.blank? }
          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

9 entries across 9 versions & 1 rubygems

Version Path
app_store_connect-0.37.0 lib/app_store_connect/object/data.rb
app_store_connect-0.36.0 lib/app_store_connect/object/data.rb
app_store_connect-0.35.0 lib/app_store_connect/object/data.rb
app_store_connect-0.34.0 lib/app_store_connect/object/data.rb
app_store_connect-0.33.0 lib/app_store_connect/object/data.rb
app_store_connect-0.32.0 lib/app_store_connect/object/data.rb
app_store_connect-0.30.0 lib/app_store_connect/object/data.rb
app_store_connect-0.29.0 lib/app_store_connect/object/data.rb
app_store_connect-0.28.0 lib/app_store_connect/object/data.rb