icalia-sdk-event-core 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/icalia-sdk-event-core/models/cloud_identity.rb +2 -0
  3. data/lib/icalia-sdk-event-core/models/code_commit.rb +1 -1
  4. data/lib/icalia-sdk-event-core/models/code_merge_request.rb +1 -1
  5. data/lib/icalia-sdk-event-core/models/code_repository.rb +1 -1
  6. data/lib/icalia-sdk-event-core/models/code_repository_reference.rb +1 -1
  7. data/lib/icalia-sdk-event-core/models/email_account.rb +10 -0
  8. data/lib/icalia-sdk-event-core/models/{code_merge_request_event.rb → events/code_merge_request_event.rb} +0 -0
  9. data/lib/icalia-sdk-event-core/models/events/membership_event.rb +11 -0
  10. data/lib/icalia-sdk-event-core/models/events/organization_event.rb +14 -0
  11. data/lib/icalia-sdk-event-core/models/membership.rb +9 -0
  12. data/lib/icalia-sdk-event-core/models/model_base.rb +31 -0
  13. data/lib/icalia-sdk-event-core/models/model_collection_proxy.rb +13 -0
  14. data/lib/icalia-sdk-event-core/models/organization.rb +2 -0
  15. data/lib/icalia-sdk-event-core/models/person.rb +2 -0
  16. data/lib/icalia-sdk-event-core/models/resource_action.rb +2 -1
  17. data/lib/icalia-sdk-event-core/models.rb +10 -2
  18. data/lib/icalia-sdk-event-core/serialization/deserializable_cloud_identity.rb +4 -5
  19. data/lib/icalia-sdk-event-core/serialization/deserializable_code_check_run.rb +1 -1
  20. data/lib/icalia-sdk-event-core/serialization/deserializable_code_check_run_event.rb +1 -1
  21. data/lib/icalia-sdk-event-core/serialization/deserializable_code_check_suite.rb +1 -2
  22. data/lib/icalia-sdk-event-core/serialization/deserializable_code_commit.rb +1 -3
  23. data/lib/icalia-sdk-event-core/serialization/deserializable_code_issue.rb +1 -3
  24. data/lib/icalia-sdk-event-core/serialization/deserializable_code_issue_occurrence.rb +1 -3
  25. data/lib/icalia-sdk-event-core/serialization/deserializable_code_merge_request.rb +1 -2
  26. data/lib/icalia-sdk-event-core/serialization/deserializable_code_merge_request_event.rb +1 -2
  27. data/lib/icalia-sdk-event-core/serialization/deserializable_code_repository.rb +1 -2
  28. data/lib/icalia-sdk-event-core/serialization/deserializable_code_repository_event.rb +1 -2
  29. data/lib/icalia-sdk-event-core/serialization/deserializable_code_repository_reference.rb +2 -5
  30. data/lib/icalia-sdk-event-core/serialization/deserializable_email_account.rb +4 -5
  31. data/lib/icalia-sdk-event-core/serialization/deserializable_membership.rb +3 -4
  32. data/lib/icalia-sdk-event-core/serialization/deserializable_membership_event.rb +2 -7
  33. data/lib/icalia-sdk-event-core/serialization/deserializable_oauth_access_token.rb +1 -2
  34. data/lib/icalia-sdk-event-core/serialization/deserializable_oauth_access_token_event.rb +1 -2
  35. data/lib/icalia-sdk-event-core/serialization/deserializable_oauth_application.rb +1 -2
  36. data/lib/icalia-sdk-event-core/serialization/deserializable_organization.rb +1 -2
  37. data/lib/icalia-sdk-event-core/serialization/deserializable_organization_event.rb +2 -7
  38. data/lib/icalia-sdk-event-core/serialization/deserializable_person.rb +5 -12
  39. data/lib/icalia-sdk-event-core/serialization/deserializable_property_resource.rb +1 -1
  40. data/lib/icalia-sdk-event-core/serialization/deserializable_resource.rb +39 -0
  41. data/lib/icalia-sdk-event-core/serialization/deserializable_resource_action.rb +1 -2
  42. data/lib/icalia-sdk-event-core/serialization/deserializable_user.rb +1 -2
  43. data/lib/icalia-sdk-event-core/serialization/deserializer.rb +21 -10
  44. data/lib/icalia-sdk-event-core/serialization.rb +8 -10
  45. data/lib/icalia-sdk-event-core/version.rb +1 -1
  46. metadata +9 -4
  47. data/lib/icalia-sdk-event-core/serialization/deserializable_resource_identity.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd11240d756598d2e451fddddd7283e486dd2fe48e82ccc46ceffb1369655a36
4
- data.tar.gz: 388c39da2cc6d4e3c4c549679610178ee231babb3d407a866269cd325be8931a
3
+ metadata.gz: 4203edefd2dcbdc0ef3bba3588d4da30686dfe5f0b009121907ac29cb8381df4
4
+ data.tar.gz: d3f61bb45612489b83d581e004d6fe51d4cb5a4280d728d62ae6d590f94a5df0
5
5
  SHA512:
6
- metadata.gz: 3a219480bdd8c1997153cecd3789c6b2f7663bf349927319e2898bfb8cc993293023af77301bbff322fed031f3c0944c18bfe8dcbd1252a62b526a0a01057976
7
- data.tar.gz: cd6db26e70dcdf41efda361068d487d99a9bae07319b645aa1dd6c1dfea1a7da731d6340da78e956b3628d85ba77f4f1f9cd2e7c0847738e1d11af11259e86b5
6
+ metadata.gz: 8761c73557e1a23729b9b62ae2ff2bc8f1be0c5d65cfa2e21d584e92093199bab4cc447a0623ee7c8f75b1b3213c849ae51cee0728bdc466887e77b8ecba86ea
7
+ data.tar.gz: 509fa5cb88d80e7ab5ff040afa31616147161c1be30856d6d0b7ec46eff7a91d3eb10f97db6e663cf6a31e3fbc9727f81420216cabb633b8de7b008b74d6e0ba
@@ -8,5 +8,7 @@ module Icalia
8
8
  :updated_at,
9
9
  :name,
10
10
  :identity_type
11
+
12
+ has_one :owner
11
13
  end
12
14
  end
@@ -4,6 +4,6 @@ module Icalia
4
4
  class CodeCommit < ModelBase
5
5
  attr_reader :sha
6
6
 
7
- attr_reader :repository
7
+ has_one :repository
8
8
  end
9
9
  end
@@ -18,7 +18,7 @@ module Icalia
18
18
  :deleted_line_count,
19
19
  :changed_file_count
20
20
 
21
- attr_reader :base, :head, :author, :committer
21
+ has_one :base, :head, :author, :committer
22
22
 
23
23
  def closed?; state == 'closed'; end
24
24
  end
@@ -4,7 +4,7 @@ module Icalia
4
4
  class CodeRepository < ModelBase
5
5
  include ResourceIdentity
6
6
 
7
- attr_reader :owner # DeserializablePropertyResource # has one owner
7
+ has_one :owner # DeserializablePropertyResource # has one owner
8
8
 
9
9
  attr_reader :created_at # include DeserializableResourceCreationTimestamp
10
10
 
@@ -5,7 +5,7 @@ module Icalia
5
5
  include ResourceIdentity
6
6
  attr_reader :name, :label
7
7
 
8
- attr_reader :commit
8
+ has_one :commit
9
9
 
10
10
  delegate :sha, :repository, to: :commit, allow_nil: true
11
11
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class EmailAccount < ModelBase
5
+ attr_reader :address,
6
+ :created_at
7
+
8
+ has_one :owner
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class MembershipEvent < ModelBase
5
+ include ResourceAction
6
+ has_one :membership
7
+
8
+ def added?; action == 'added'; end
9
+ def removed?; action == 'removed'; end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class OrganizationEvent < ModelBase
5
+ include ResourceAction
6
+
7
+ has_one :organization
8
+
9
+ def created?; action == 'created'; end
10
+ def deleted?; action == 'deleted'; end
11
+ def renamed?; action == 'renamed'; end
12
+ def updated?; action == 'updated'; end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class Membership < ModelBase
5
+ attr_reader :created_at
6
+
7
+ has_one :member, :group
8
+ end
9
+ end
@@ -9,18 +9,49 @@ module Icalia
9
9
 
10
10
  attr_reader :serialization_context
11
11
 
12
+ cattr_reader(:associated_resources) { [] }
13
+ cattr_reader(:associated_resource_collections) { [] }
14
+
12
15
  def initialize(object_attributes = {})
13
16
  @serialization_context = object_attributes.delete :serialization_context
14
17
 
15
18
  object_attributes.each do |key, value|
16
19
  attribute_name = "#{key}".underscore
17
20
  next register_stand_in(attribute_name, value) if value.is_a? ModelProxy
21
+ next register_collection(attribute_name, value) if value.is_a? Array
18
22
  instance_variable_set("@#{attribute_name}", value)
19
23
  end
20
24
  end
21
25
 
26
+ class << self
27
+ def has_one(*associations)
28
+ associations.each do |association|
29
+ attr_reader association
30
+ associated_resources << association
31
+ end
32
+ end
33
+
34
+ def has_many(*associations)
35
+ associations.each do |association|
36
+ attr_reader association
37
+ associated_resource_collections << association
38
+ end
39
+ end
40
+ end
41
+
22
42
  private
23
43
 
44
+ def register_collection(association, collection)
45
+ instance_variable_set("@#{association}", collection)
46
+ collection.each_with_index do |item, index|
47
+ next unless item.is_a? ModelProxy
48
+ serialization_context.register_stand_in model: self,
49
+ index: index,
50
+ stand_in: item,
51
+ association: association
52
+ end
53
+ end
54
+
24
55
  def register_stand_in(association, stand_in)
25
56
  instance_variable_set("@#{association}", stand_in)
26
57
  serialization_context.register_stand_in model: self,
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ # ModelCollectionProxy: Acts as a stand-in for an associated model collection,
5
+ # which may be awaiting for de-serialization at the time the parent object was
6
+ # being de-serialized
7
+ class ModelCollectionProxy
8
+
9
+ def initialize(links: {})
10
+ @links = links
11
+ end
12
+ end
13
+ end
@@ -4,5 +4,7 @@ module Icalia
4
4
  class Organization < ModelBase
5
5
  include ResourceTimestamps
6
6
  attr_reader :name
7
+
8
+ has_many :email_accounts, :cloud_identities
7
9
  end
8
10
  end
@@ -4,5 +4,7 @@ module Icalia
4
4
  class Person < ModelBase
5
5
  include ResourceTimestamps
6
6
  attr_reader :name
7
+
8
+ has_many :email_accounts, :cloud_identities
7
9
  end
8
10
  end
@@ -5,7 +5,8 @@ module Icalia
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- attr_reader :action, :actor, :timestamp
8
+ attr_reader :action, :timestamp
9
+ has_one :actor
9
10
  end
10
11
  end
11
12
  end
@@ -5,7 +5,7 @@ module Icalia
5
5
 
6
6
  autoload :ModelBase, "#{models_path}/model_base"
7
7
  autoload :ModelProxy, "#{models_path}/model_proxy"
8
-
8
+ autoload :ModelCollectionProxy, "#{models_path}/model_collection_proxy"
9
9
 
10
10
  autoload :ResourceIdentity, "#{models_path}/resource_identity"
11
11
  autoload :ResourceAction, "#{models_path}/resource_action"
@@ -15,6 +15,11 @@ module Icalia
15
15
  autoload :Person, "#{models_path}/person"
16
16
  autoload :Organization, "#{models_path}/organization"
17
17
 
18
+ autoload :EmailAccount, "#{models_path}/email_account"
19
+ autoload :CloudIdentity, "#{models_path}/cloud_identity"
20
+
21
+ autoload :Membership, "#{models_path}/membership"
22
+
18
23
  autoload :CodeCommit, "#{models_path}/code_commit"
19
24
  autoload :CodeRepository, "#{models_path}/code_repository"
20
25
  autoload :CodeRepositoryReference, "#{models_path}/code_repository_reference"
@@ -22,5 +27,8 @@ module Icalia
22
27
  autoload :CodeMergeRequest, "#{models_path}/code_merge_request"
23
28
 
24
29
  # Event Models:
25
- autoload :CodeMergeRequestEvent, "#{models_path}/code_merge_request_event"
30
+ event_models_path = "#{models_path}/events"
31
+ autoload :MembershipEvent, "#{event_models_path}/membership_event"
32
+ autoload :OrganizationEvent, "#{event_models_path}/organization_event"
33
+ autoload :CodeMergeRequestEvent, "#{event_models_path}/code_merge_request_event"
26
34
  end
@@ -5,17 +5,16 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `User` object
8
- class DeserializableCloudIdentity < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializableCloudIdentity < DeserializableResource
10
9
  include DeserializableResourceTimestamps
11
10
 
12
11
  attributes :name, :provider
13
12
 
14
- attribute(:'identity-type') { |value| Hash[type: value] }
15
- attribute(:'id-at-provider') { |value| Hash[uid: value.to_s] }
13
+ attribute(:'identity-type') { |value| Hash[identity_type: value] }
14
+ attribute(:'id-at-provider') { |value| Hash[id_at_provider: value.to_s] }
16
15
 
17
16
  has_one :owner do |_rel, id, type|
18
- Hash[owner_id: id, owner_type: classify_type(type)]
17
+ Hash[owner: get_stand_in(id: id, type: classify_type(type))]
19
18
  end
20
19
  end
21
20
  end
@@ -3,7 +3,7 @@ module Icalia::Event
3
3
  #
4
4
  # This class is responsible for converting a JSONAPI.org representation
5
5
  # of an Icalia Event's `CheckRun` object
6
- class DeserializableCheckRun < JSONAPI::Deserializable::Resource
6
+ class DeserializableCheckRun < DeserializableResource
7
7
  include DeserializableResourceTimestamps
8
8
 
9
9
  id { |value| Hash[unique_id: value] }
@@ -3,7 +3,7 @@ module Icalia::Event
3
3
  #
4
4
  # This class is responsible for converting a JSONAPI.org representation
5
5
  # of an Icalia Event's `CodeCheckRunEvent` object
6
- class DeserializableCodeCheckRunEvent < JSONAPI::Deserializable::Resource
6
+ class DeserializableCodeCheckRunEvent < DeserializableResource
7
7
  include DeserializableResourceAction
8
8
  include DeserializableResourceCreationTimestamp
9
9
 
@@ -3,8 +3,7 @@ module Icalia::Event
3
3
  #
4
4
  # This class is responsible for converting a JSONAPI.org representation
5
5
  # of an Icalia Event's `CodeCheckRunEvent` object
6
- class DeserializableCodeCheckRunEvent < JSONAPI::Deserializable::Resource
7
- include DeserializableResourceIdentity
6
+ class DeserializableCodeCheckRunEvent < DeserializableResource
8
7
  include DeserializableResourceAction
9
8
  include DeserializableResourceCreationTimestamp
10
9
 
@@ -5,9 +5,7 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia `CodeCommitReference` object
8
- class DeserializableCodeCommit < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity # id and type
10
-
8
+ class DeserializableCodeCommit < DeserializableResource
11
9
  attributes :sha
12
10
 
13
11
  has_one(:repository) do |_rel, id, type|
@@ -6,9 +6,7 @@ module Icalia::Event
6
6
  # Converts a JSONAPI.org serialization of a `CodeIssue` object from a
7
7
  # Notification topic into an `ActionController::Parameters` object that can be
8
8
  # used to create or update code issue data
9
- class DeserializableCodeIssue < JSONAPI::Deserializable::Resource
10
- include DeserializableResourceIdentity
11
-
9
+ class DeserializableCodeIssue < DeserializableResource
12
10
  LOCATION_DATA_KEYS = %w[path start-line end-line]
13
11
 
14
12
  def self.deserialize_location_data(location_data)
@@ -6,9 +6,7 @@ module Icalia::Event
6
6
  # Converts a JSONAPI.org serialization of a `CodeIssueOcurrence` object
7
7
  # notification into an `ActionController::Parameters` object that can be used
8
8
  # to create or update repo data
9
- class DeserializableCodeIssueOccurrence < JSONAPI::Deserializable::Resource
10
- include DeserializableResourceIdentity
11
-
9
+ class DeserializableCodeIssueOccurrence < DeserializableResource
12
10
  has_one(:'check-run') { |_rel, id, _type| Hash[check_run_unique_id: id] }
13
11
 
14
12
  has_one(:issue) { |_rel, id, _type| Hash[code_issue_id: id] }
@@ -6,8 +6,7 @@ module Icalia::Event
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `CodeMergeRequestEvent` object that can be used to create or
8
8
  # update a code-repository data
9
- class DeserializableCodeMergeRequest < JSONAPI::Deserializable::Resource
10
- include DeserializableResourceIdentity
9
+ class DeserializableCodeMergeRequest < DeserializableResource
11
10
  include DeserializableResourceTimestamps
12
11
 
13
12
  attributes :number, :provider, :body, :state, :title, :url, :additions, :deletions
@@ -6,8 +6,7 @@ module Icalia::Event
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `CodeMergeRequestEvent` object that can be used to create or
8
8
  # update a code-repository data
9
- class DeserializableCodeMergeRequestEvent < JSONAPI::Deserializable::Resource
10
- include DeserializableResourceIdentity
9
+ class DeserializableCodeMergeRequestEvent < DeserializableResource
11
10
  include DeserializableResourceAction
12
11
 
13
12
  has_one :'merge-request' do |_rel, id, type|
@@ -5,8 +5,7 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `CodeRepository` object
8
- class DeserializableCodeRepository < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity # id and type
8
+ class DeserializableCodeRepository < DeserializableResource
10
9
  include DeserializablePropertyResource # has one owner
11
10
  include DeserializableResourceCreationTimestamp
12
11
 
@@ -6,8 +6,7 @@ module Icalia::Event
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `CodeRepositoryEvent` object that can be used to create or
8
8
  # update a code-repository data
9
- class DeserializableCodeRepositoryEvent < JSONAPI::Deserializable::Resource
10
- include DeserializableResourceIdentity
9
+ class DeserializableCodeRepositoryEvent < DeserializableResource
11
10
  include DeserializableResourceAction
12
11
  include DeserializableResourceCreationTimestamp
13
12
 
@@ -5,14 +5,11 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia `CodeRepositoryReference` object
8
- class DeserializableCodeRepositoryReference < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity # id and type
10
-
8
+ class DeserializableCodeRepositoryReference < DeserializableResource
11
9
  attributes :name, :label
12
10
 
13
11
  has_one(:commit) do |_rel, id, type|
14
- stand_in = Icalia::ModelProxy.new id: id, type: classify_type(type)
15
- Hash[commit: stand_in]
12
+ Hash[commit: get_stand_in(id: id, type: classify_type(type))]
16
13
  end
17
14
  end
18
15
  end
@@ -6,14 +6,13 @@ module Icalia::Event
6
6
  # Converts a JSONAPI.org serialization of a `EmailAccount` object from a
7
7
  # Notification topic into an `ActionController::Parameters` object that can be
8
8
  # used to create or update an email account
9
- class DeserializableEmailAccount < JSONAPI::Deserializable::Resource
10
- include DeserializableResourceIdentity
11
-
9
+ class DeserializableEmailAccount < DeserializableResource
10
+ include DeserializableResourceCreationTimestamp
11
+
12
12
  attribute :address
13
- attribute(:'created-at') { |value| Hash[created_at: value] }
14
13
 
15
14
  has_one :owner do |_rel, id, type|
16
- Hash[owner_id: id, owner_type: classify_type(type)]
15
+ Hash[owner: get_stand_in(id: id, type: classify_type(type))]
17
16
  end
18
17
  end
19
18
  end
@@ -5,16 +5,15 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `Membership` object
8
- class DeserializableMembership < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializableMembership < DeserializableResource
10
9
  include DeserializableResourceCreationTimestamp
11
10
 
12
11
  has_one :member do |_rel, id, type|
13
- Hash[member_id: id, member_type: classify_type(type)]
12
+ Hash[member: get_stand_in(id: id, type: classify_type(type))]
14
13
  end
15
14
 
16
15
  has_one :group do |_rel, id, type|
17
- Hash[group_id: id, group_type: classify_type(type)]
16
+ Hash[group: get_stand_in(id: id, type: classify_type(type))]
18
17
  end
19
18
  end
20
19
  end
@@ -5,17 +5,12 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `MembershipEvent` object
8
- class DeserializableMembershipEvent < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializableMembershipEvent < DeserializableResource
10
9
  include DeserializableResourceAction
11
10
  include DeserializableResourceCreationTimestamp
12
11
 
13
12
  has_one :membership do |_rel, id, type|
14
- Hash[membership_id: id, membership_type: classify_type(type)]
15
- end
16
-
17
- has_one :sender do |_rel, id, type|
18
- Hash[sender_id: id, sender_type: classify_type(type)]
13
+ Hash[membership: get_stand_in(id: id, type: classify_type(type))]
19
14
  end
20
15
  end
21
16
  end
@@ -5,8 +5,7 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia OAuth Access Token
8
- class DeserializableOauthAccessToken < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializableOauthAccessToken < DeserializableResource
10
9
  include DeserializableResourceCreationTimestamp
11
10
 
12
11
  attributes :scopes
@@ -5,8 +5,7 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia OAuth Access Token event
8
- class DeserializableOauthAccessTokenEvent < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializableOauthAccessTokenEvent < DeserializableResource
10
9
  include DeserializableResourceAction
11
10
  include DeserializableResourceCreationTimestamp
12
11
 
@@ -5,8 +5,7 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia OAuth Application
8
- class DeserializableOauthApplication < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializableOauthApplication < DeserializableResource
10
9
  include DeserializableResourceTimestamps
11
10
 
12
11
  attributes :name
@@ -5,8 +5,7 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `Organization` object
8
- class DeserializableOrganization < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity # id and type
8
+ class DeserializableOrganization < DeserializableResource
10
9
  include DeserializablePropertyResource # has one owner
11
10
  include DeserializableResourceTimestamps # created_at and updated_at
12
11
 
@@ -5,17 +5,12 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `OrganizationEvent` object
8
- class DeserializableOrganizationEvent < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializableOrganizationEvent < DeserializableResource
10
9
  include DeserializableResourceAction
11
10
  include DeserializableResourceCreationTimestamp
12
11
 
13
12
  has_one :organization do |_rel, id, type|
14
- Hash[organization_id: id, organization_type: classify_type(type)]
15
- end
16
-
17
- has_one :sender do |_rel, id, type|
18
- Hash[sender_id: id, sender_type: classify_type(type)]
13
+ Hash[organization: get_stand_in(id: id, type: classify_type(type))]
19
14
  end
20
15
  end
21
16
  end
@@ -5,24 +5,17 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `Person` object
8
- class DeserializablePerson < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializablePerson < DeserializableResource
10
9
  include DeserializableResourceTimestamps
11
10
 
12
11
  attributes :name
13
12
 
14
- has_many(:'email-accounts') do |_rel, ids, types|
15
- Hash[
16
- email_account_ids: ids,
17
- email_account_types: types.map { |type| classify_type(type) }
18
- ]
13
+ has_many(:'email-accounts') do |rel, _ids, _types|
14
+ Hash[email_accounts: get_stand_ins(rel)]
19
15
  end
20
16
 
21
- has_many(:'cloud-identities') do |_rel, ids, types|
22
- Hash[
23
- cloud_identity_ids: ids,
24
- cloud_identity_types: types.map { |type| classify_type(type) }
25
- ]
17
+ has_many(:'cloud-identities') do |rel, _ids, _types|
18
+ Hash[cloud_identities: get_stand_ins(rel)]
26
19
  end
27
20
  end
28
21
  end
@@ -6,7 +6,7 @@ module Icalia::Event
6
6
 
7
7
  included do
8
8
  has_one :owner do |_rel, id, type|
9
- Hash[owner_id: id, owner_type: classify_type(type)]
9
+ Hash[owner: get_stand_in(id: id, type: classify_type(type))]
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia::Event
4
+ class DeserializableResource < JSONAPI::Deserializable::Resource
5
+
6
+ delegate :classify_type,
7
+ :classify_data,
8
+ :get_stand_in,
9
+ :get_stand_ins,
10
+ to: :class
11
+
12
+ id { |value| Hash[id: value] }
13
+ type { |value| Hash[type: classify_type(value)] }
14
+
15
+ class << self
16
+ def classify_type(type)
17
+ type.underscore.camelize
18
+ end
19
+
20
+ def classify_data(data)
21
+ classify_type data['type']
22
+ end
23
+
24
+ def get_stand_in(id:, type:)
25
+ Icalia::ModelProxy.new id: id, type: type
26
+ end
27
+
28
+ def get_stand_ins(rel)
29
+ if rel['data'].nil?
30
+ Icalia::Event::ModelCollectionProxy.new rel['links']
31
+ else
32
+ rel['data'].map do |data|
33
+ get_stand_in id: data['id'], type: classify_data(data)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -9,8 +9,7 @@ module Icalia::Event
9
9
  attribute(:timestamp) { |value| Hash[timestamp: Time.parse(value)] }
10
10
 
11
11
  has_one :actor do |_rel, id, type|
12
- stand_in = Icalia::ModelProxy.new id: id, type: classify_type(type)
13
- Hash[actor: stand_in]
12
+ Hash[actor: get_stand_in(id: id, type: classify_type(type))]
14
13
  end
15
14
  end
16
15
  end
@@ -5,8 +5,7 @@ module Icalia::Event
5
5
  #
6
6
  # This class is responsible for converting a JSONAPI.org representation of an
7
7
  # Icalia Event's `User` object
8
- class DeserializableUser < JSONAPI::Deserializable::Resource
9
- include DeserializableResourceIdentity
8
+ class DeserializableUser < DeserializableResource
10
9
  include DeserializableResourceTimestamps
11
10
 
12
11
  attributes :email
@@ -1,16 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/inflector'
4
+
3
5
  module Icalia::Event
4
6
  class Deserializer
5
7
  attr_reader :data
6
8
 
7
9
  class StandInReplacement
8
- attr_reader :model, :association, :stand_in
10
+ attr_reader :model, :association, :stand_in, :index
9
11
 
10
- def initialize(model:, association:, stand_in:)
12
+ def initialize(model:, association:, stand_in:, index: nil)
11
13
  @model = model
12
14
  @association = association
13
15
  @stand_in = stand_in
16
+ @index = index
14
17
  end
15
18
  end
16
19
 
@@ -21,7 +24,7 @@ module Icalia::Event
21
24
  end
22
25
 
23
26
  def perform
24
- return @data if @data.present?
27
+ return @data if @data
25
28
  deserialize_included
26
29
  deserialize_data
27
30
  replace_stand_ins
@@ -29,11 +32,12 @@ module Icalia::Event
29
32
  @data
30
33
  end
31
34
 
32
- def register_stand_in(model:, association:, stand_in:)
35
+ def register_stand_in(model:, association:, stand_in:, index: nil)
33
36
  @pending_stand_in_replacements << StandInReplacement.new(
34
37
  model: model,
35
38
  association: association,
36
- stand_in: stand_in
39
+ stand_in: stand_in,
40
+ index: index
37
41
  )
38
42
  end
39
43
 
@@ -49,10 +53,17 @@ module Icalia::Event
49
53
 
50
54
  def replace_stand_ins
51
55
  @pending_stand_in_replacements.each do |replacement|
52
- associated_object = @objects[replacement.stand_in.to_key]
53
- next unless associated_object.present?
56
+ next unless associated_object = @objects[replacement.stand_in.to_key]
57
+
58
+ model = replacement.model
59
+ index = replacement.index
54
60
  variable = "@#{replacement.association}".to_sym
55
- replacement.model.instance_variable_set(variable, associated_object)
61
+
62
+ if index
63
+ model.instance_variable_get(variable)[index] = associated_object
64
+ else
65
+ model.instance_variable_set(variable, associated_object)
66
+ end
56
67
  end
57
68
  end
58
69
 
@@ -82,10 +93,10 @@ module Icalia::Event
82
93
  def deserialize_object_data(object_data)
83
94
  object_class_name = object_data['type'].underscore.classify
84
95
  object_class = "::Icalia::#{object_class_name}".safe_constantize
85
- return unless object_class.present?
96
+ return unless object_class
86
97
 
87
98
  deserializer_class = "::Icalia::Event::Deserializable#{object_class_name}".safe_constantize
88
- return unless deserializer_class.present?
99
+ return unless deserializer_class
89
100
 
90
101
  object_attributes = deserializer_class
91
102
  .call(object_data)
@@ -9,9 +9,6 @@ module Icalia
9
9
  autoload :Deserializer, "#{serialization_path}/deserializer"
10
10
 
11
11
  # Deserialization Modules:
12
- autoload :DeserializableResourceIdentity,
13
- "#{serialization_path}/deserializable_resource_identity"
14
-
15
12
  autoload :DeserializableResourceAction,
16
13
  "#{serialization_path}/deserializable_resource_action"
17
14
 
@@ -25,26 +22,30 @@ module Icalia
25
22
  "#{serialization_path}/deserializable_property_resource"
26
23
 
27
24
  # Event deserialization
28
-
29
25
  autoload :DeserializableMembershipEvent,
30
26
  "#{serialization_path}/deserializable_membership_event"
31
27
 
32
28
  autoload :DeserializableOrganizationEvent,
33
29
  "#{serialization_path}/deserializable_organization_event"
34
30
 
31
+ autoload :DeserializableCodeMergeRequestEvent,
32
+ "#{serialization_path}/deserializable_code_merge_request_event"
33
+
35
34
  autoload :DeserializableOauthAccessTokenEvent,
36
35
  "#{serialization_path}/deserializable_oauth_access_token_event"
37
36
 
38
37
  # Deserializable Objects
39
-
40
- autoload :DeserializableMembership,
41
- "#{serialization_path}/deserializable_membership"
38
+ autoload :DeserializableResource,
39
+ "#{serialization_path}/deserializable_resource"
42
40
 
43
41
  autoload :DeserializableEmailAccount,
44
42
  "#{serialization_path}/deserializable_email_account"
45
43
 
46
44
  autoload :DeserializableUser,
47
45
  "#{serialization_path}/deserializable_user"
46
+
47
+ autoload :DeserializableMembership,
48
+ "#{serialization_path}/deserializable_membership"
48
49
 
49
50
  autoload :DeserializablePerson,
50
51
  "#{serialization_path}/deserializable_person"
@@ -64,9 +65,6 @@ module Icalia
64
65
  autoload :DeserializableCodeMergeRequest,
65
66
  "#{serialization_path}/deserializable_code_merge_request"
66
67
 
67
- autoload :DeserializableCodeMergeRequestEvent,
68
- "#{serialization_path}/deserializable_code_merge_request_event"
69
-
70
68
  autoload :DeserializableCodeCommit,
71
69
  "#{serialization_path}/deserializable_code_commit"
72
70
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Icalia
4
4
  module Event
5
- CORE_VERSION = '0.3.1'
5
+ CORE_VERSION = '0.3.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icalia-sdk-event-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Quintanilla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-07 00:00:00.000000000 Z
11
+ date: 2020-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-deserializable
@@ -93,10 +93,15 @@ files:
93
93
  - lib/icalia-sdk-event-core/models/cloud_identity.rb
94
94
  - lib/icalia-sdk-event-core/models/code_commit.rb
95
95
  - lib/icalia-sdk-event-core/models/code_merge_request.rb
96
- - lib/icalia-sdk-event-core/models/code_merge_request_event.rb
97
96
  - lib/icalia-sdk-event-core/models/code_repository.rb
98
97
  - lib/icalia-sdk-event-core/models/code_repository_reference.rb
98
+ - lib/icalia-sdk-event-core/models/email_account.rb
99
+ - lib/icalia-sdk-event-core/models/events/code_merge_request_event.rb
100
+ - lib/icalia-sdk-event-core/models/events/membership_event.rb
101
+ - lib/icalia-sdk-event-core/models/events/organization_event.rb
102
+ - lib/icalia-sdk-event-core/models/membership.rb
99
103
  - lib/icalia-sdk-event-core/models/model_base.rb
104
+ - lib/icalia-sdk-event-core/models/model_collection_proxy.rb
100
105
  - lib/icalia-sdk-event-core/models/model_proxy.rb
101
106
  - lib/icalia-sdk-event-core/models/organization.rb
102
107
  - lib/icalia-sdk-event-core/models/person.rb
@@ -126,9 +131,9 @@ files:
126
131
  - lib/icalia-sdk-event-core/serialization/deserializable_organization_event.rb
127
132
  - lib/icalia-sdk-event-core/serialization/deserializable_person.rb
128
133
  - lib/icalia-sdk-event-core/serialization/deserializable_property_resource.rb
134
+ - lib/icalia-sdk-event-core/serialization/deserializable_resource.rb
129
135
  - lib/icalia-sdk-event-core/serialization/deserializable_resource_action.rb
130
136
  - lib/icalia-sdk-event-core/serialization/deserializable_resource_creation_timestamp.rb
131
- - lib/icalia-sdk-event-core/serialization/deserializable_resource_identity.rb
132
137
  - lib/icalia-sdk-event-core/serialization/deserializable_resource_timestamps.rb
133
138
  - lib/icalia-sdk-event-core/serialization/deserializable_user.rb
134
139
  - lib/icalia-sdk-event-core/serialization/deserializer.rb
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Icalia::Event
4
- module DeserializableResourceIdentity
5
- extend ActiveSupport::Concern
6
-
7
- delegate :classify_type, to: :class
8
-
9
- included do
10
- id { |value| Hash[id: value] }
11
- type { |value| Hash[type: classify_type(value)] }
12
- end
13
-
14
- module ClassMethods
15
- def classify_type(type)
16
- type.underscore.camelize
17
- end
18
- end
19
- end
20
- end