Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Included Concern #135

Merged
merged 9 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/app_store_connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'app_store_connect/object/id'
require 'app_store_connect/object/attributes'
require 'app_store_connect/object/properties'
require 'app_store_connect/object/included'
kyledecot marked this conversation as resolved.
Show resolved Hide resolved
require 'app_store_connect/object/data'
require 'app_store_connect/version'

Expand Down
10 changes: 10 additions & 0 deletions lib/app_store_connect/create_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ module AppStoreConnect
class CreateRequest
def self.inherited(klass)
super

klass.include(Object::Included)
klass.include(Object::Data)
end

def initialize(**kwargs)
@included = self.class::Included.new([*kwargs.delete(:included)])
@data = self.class::Data.new(**kwargs)
end

def to_h
{
data: data.to_h,
included: included.to_a
}
end
end
end
12 changes: 11 additions & 1 deletion lib/app_store_connect/modify_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ module AppStoreConnect
class ModifyRequest
kyledecot marked this conversation as resolved.
Show resolved Hide resolved
def self.inherited(klass)
super

klass.include(Object::Included)
klass.include(Object::Data)
end

def initialize(**kwargs)
@data = self.class::Data.new(kwargs)
@included = self.class::Included.new([*kwargs.delete(:included)])
@data = self.class::Data.new(**kwargs)
end

def to_h
{
data: data.to_h,
included: included.to_a
}
end
end
end
6 changes: 0 additions & 6 deletions lib/app_store_connect/object/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ def to_h
end

const_set('Data', klass)

def to_h
{
data: data.to_h
}
end
end

class_methods do
Expand Down
27 changes: 27 additions & 0 deletions lib/app_store_connect/object/included.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'active_support/concern'

module AppStoreConnect
module Object
module Included
extend ActiveSupport::Concern

included do
attr_reader :included

klass = Class.new do |i|
i.send(:define_method, :initialize) do |objects|
instance_variable_set('@objects', [*objects])
end

def to_a
@objects
end
end

const_set('Included', klass)
kyledecot marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
6 changes: 4 additions & 2 deletions spec/bundle_id_create_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
name: attributes.name,
platform: attributes.platform
}
}
},
included: []
)
end
end
Expand All @@ -36,7 +37,8 @@
seed_id: attributes.seed_id,
platform: attributes.platform
}
}
},
included: []
kyledecot marked this conversation as resolved.
Show resolved Hide resolved
)
end
end
Expand Down