arkaan 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b30a877a72ebfbb8d01fa95128e204c48d4791c
4
- data.tar.gz: f149d7e43ecb9ee6ea9a11b3b270a3f6e87f7ec5
3
+ metadata.gz: 4d869f90d4cee592c70b846266cdf3bfcc9610bc
4
+ data.tar.gz: 0de454de233032c6569f33e940336c68385630f9
5
5
  SHA512:
6
- metadata.gz: 6a1523574507d5058179b59e9028fdd588209c3eb9abfe3dd4338b0daddaed65a1d7482ffc14da77fc3ac2e47b4b49f847c2597bcc56ca0f2c214aa3533bf54d
7
- data.tar.gz: 3e84a861858ffae9585c4dbd7db1e1079002b5ec1238a006ea4aff379eafb79f7dc3abb56a44cb81befc7aec764915281f79310399f61531f5ca1d00ee4b8db9
6
+ metadata.gz: f195db87e476d287d1c5f6966446a71f62ff76d3e0b31ec0ab5ad3b2c8063b4e42cdacf2c7f498d84a701b1acb0e4c804df9250b473c3113b0cea361ded9671b
7
+ data.tar.gz: e72667ef1913a4edadcb41e97c7f0c2c2ebfee178c1c82b1221c9f879e3f3329976bd50f71591ad27d0afef524a623bcfa0905d51d040d9b41a01bc8e94cc32d
@@ -44,9 +44,6 @@ module Arkaan
44
44
  # @!attribute [rw] sessions
45
45
  # @return [Array<Arkaan::Authentication::Session>] the sessions on which this account is, or has been logged in.
46
46
  has_many :sessions, class_name: 'Arkaan::Authentication::Session', inverse_of: :account
47
- # @!attribute [rw] campaigns
48
- # @return [Array<Arkaan::Campaign>] the campaigns this account has created.
49
- has_many :campaigns, class_name: 'Arkaan::Campaign', inverse_of: :creator
50
47
  # @!attribute [rw] invitations
51
48
  # @return [Array<Arkaan::Campaigns::Invitation>] the invitations in campaigns you have been issued.
52
49
  has_many :invitations, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :account
@@ -21,10 +21,6 @@ module Arkaan
21
21
  # @return [Integer] the maximum number of players allowed in this campaign.
22
22
  field :max_players, type: Integer, default: 5
23
23
 
24
- # @!attribute [rw] creator
25
- # @return [Arkaan::Campaign] the account creating the campaign, and considered "game master".
26
- belongs_to :creator, class_name: 'Arkaan::Account', inverse_of: :campaigns
27
-
28
24
  # @!attribute [rw] invitations
29
25
  # @return [Array<Arkaan::Campaigns::Invitation>] the invitations to players that have been made for this campaign.
30
26
  has_many :invitations, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :campaign
@@ -39,9 +35,27 @@ module Arkaan
39
35
 
40
36
  validate :title_unicity
41
37
 
38
+ # Sets the creator of the campaign. This method is mainly used for backward-compatibility needs.
39
+ # @param account [Arkaan::Account] the account of the creator for this campaign.
40
+ def creator=(account)
41
+ if !invitations.where(account: account).exists?
42
+ Arkaan::Campaigns::Invitation.create(campaign: self, account: account, enum_status: :creator)
43
+ end
44
+ end
45
+
46
+ # Getter for the creator account of this campaign.
47
+ # @return [Arkaan::Account] the account of the player creating this campaign.
48
+ def creator
49
+ return invitations.where(enum_status: :creator).first.account
50
+ end
51
+
42
52
  # Adds an error message if the account creating this campaign already has a campaign with the very same name.
43
53
  def title_unicity
44
- if creator? && title? && creator.campaigns.where(title: title, :id.ne => _id).exists?
54
+ # First we take all the other campaign ids of the user.
55
+ campaign_ids = creator.invitations.where(:campaign_id.ne => _id).pluck(:campaign_id)
56
+ # With this list of campaign IDs, we look for a campaign with the same title.
57
+ same_title_campaign = Arkaan::Campaign.where(:_id.in => campaign_ids, title: title)
58
+ if !creator.nil? && title? && same_title_campaign.exists?
45
59
  errors.add(:title, 'uniq')
46
60
  end
47
61
  end
@@ -9,7 +9,7 @@ module Arkaan
9
9
 
10
10
  # @!attribute [rw] status
11
11
  # @return [Symbol] the current status of the invitation.
12
- enum_field :status, [:accepted, :blocked, :expelled, :ignored, :left, :pending, :refused, :request], default: :pending
12
+ enum_field :status, [:accepted, :blocked, :expelled, :ignored, :left, :pending, :refused, :request, :creator], default: :pending
13
13
 
14
14
  # @!attribute [rw] account
15
15
  # @return [Arkaan::Account] the account the invitation has been issued to.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkaan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-22 00:00:00.000000000 Z
11
+ date: 2018-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec