arkaan 1.3.11 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3453ca2f5008c85b237f6db1f5a83d829e5d8bb1
4
- data.tar.gz: f9ba7f3c279e3b4ccaf8a38fd57f66d73ae29c74
3
+ metadata.gz: 1e39623177ee5030ea01c5247ff141e16cf822ff
4
+ data.tar.gz: c6ece8164773ae0dbd40cdb9f81ea2cb3f51ff2e
5
5
  SHA512:
6
- metadata.gz: 80afc1f50745c3cf5e588b14c2e26460740c83aa923c9fbd3f80fce272a287497c0af862b3e8a53ed578a2651c8c2c3f462a27f0eae0cb7f402542585c67096b
7
- data.tar.gz: 819afc88221dc311648a4070df1f45af95d7f115c112fe409a8cc0e3ea6f22f3894106ade2167ead0d4563fdf13df77c02878077212294471e0cc3308c244f33
6
+ metadata.gz: a7a0158cf4887d94e9213497c0281076ddabdd230884d1fc5b7fd605376f3568b303aeedada76ba685a4696c6678dad53668441323e9300fc00580e144ca26c4
7
+ data.tar.gz: c37f7e89de3de5a144233b69cddae20baa1a2670a0f1513dd9e95c9f3d1bcface464d0fcb92ae43aa80c75cd0096b9af44021b77bb0d574e64bd747ee67feb9c
@@ -19,8 +19,11 @@ module Arkaan
19
19
  autoload :Decorators , 'arkaan/decorators'
20
20
  autoload :Factories , 'arkaan/factories'
21
21
  autoload :Monitoring , 'arkaan/monitoring'
22
+ autoload :Notification , 'arkaan/notification'
22
23
  autoload :OAuth , 'arkaan/oauth'
23
24
  autoload :Permissions , 'arkaan/permissions'
24
25
  autoload :Phone , 'arkaan/phone'
26
+ autoload :Ruleset , 'arkaan/ruleset'
27
+ autoload :Rulesets , 'arkaan/rulesets'
25
28
  autoload :Utils , 'arkaan/utils'
26
29
  end
@@ -64,6 +64,19 @@ module Arkaan
64
64
  # @!attribute [rw] phones
65
65
  # @return [Array<Arkaan::Phone>] the phone numbers given by the user.
66
66
  embeds_many :phones, class_name: 'Arkaan::Phone', inverse_of: :account
67
+ # @!attribute [rw] notifications
68
+ # @return [Array<Arkaan::Notification>] the notifications linked to this user.
69
+ embeds_many :notifications, class_name: 'Arkaan::Notification', inverse_of: :account
70
+
71
+ # @return [Array<Arkaan::Notification>] the unread notifications that should be displayed first for the user.
72
+ def unread_notifications
73
+ notifications.where(read: false)
74
+ end
75
+
76
+ # @return [Array<Arkaan::Notification>] the notifications already read, less important to display than the unread ones.
77
+ def read_notifications
78
+ notifications.where(read: true)
79
+ end
67
80
 
68
81
  validates :username,
69
82
  presence: {message: 'required'},
@@ -24,6 +24,9 @@ module Arkaan
24
24
  # @!attribute [rw] invitations
25
25
  # @return [Array<Arkaan::Campaigns::Invitation>] the invitations to players that have been made for this campaign.
26
26
  has_many :invitations, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :campaign
27
+ # @!attribute [rw] files
28
+ # @return [Array<Arkaan::Campaigns::File>] the list of files that were uploaded in this campaign.
29
+ has_many :files, class_name: 'Arkaan::Campaigns::File', inverse_of: :campaign
27
30
 
28
31
  # @!attribute [rw] messages
29
32
  # @return [Array<Arkaan::Campaigns::Messages::Base>] the messages sent in the chatroom of the campaign.
@@ -2,9 +2,12 @@ module Arkaan
2
2
  # The campaigns module is holding the logic for some objects related to campaigns.
3
3
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
4
  module Campaigns
5
+ autoload :Document , 'arkaan/campaigns/document'
5
6
  autoload :File , 'arkaan/campaigns/file'
7
+ autoload :Files , 'arkaan/campaigns/files'
6
8
  autoload :Invitation, 'arkaan/campaigns/invitation'
7
9
  autoload :Message , 'arkaan/campaigns/message'
10
+ autoload :Note , 'arkaan/campaigns/note'
8
11
  autoload :Tag , 'arkaan/campaigns/tag'
9
12
  end
10
13
  end
@@ -0,0 +1,54 @@
1
+ module Arkaan
2
+ module Campaigns
3
+ # A document is any piece of data added by a user to a campaign. It can either be a direct text note, or an uploaded file for example.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class Document
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ # @!attribute [rw] permission
10
+ # @return [Arkaan::Campaigns::Permission] the permissions granted to the different users of the campaign concerning this file.
11
+ has_many :permissions, class_name: 'Arkaan::Campaigns::Files::Permission', inverse_of: :file
12
+
13
+ # @!attribute [rw] campaign
14
+ # @return [Arkaan::Campaign] the campaign in which this file was uploaded.
15
+ belongs_to :campaign, class_name: 'Arkaan::Campaign', inverse_of: :files
16
+
17
+ # Custom setter for the creator of the file so that it can be used as a normal field.
18
+ # @param invitation [Arkaan::Campaigns::Invitation] the invitation of the player creating this file.
19
+ def creator=(invitation)
20
+ if !permissions.where(invitation: invitation).exists?
21
+ Arkaan::Campaigns::Files::Permission.create(enum_level: :creator, file: self, invitation: invitation)
22
+ end
23
+ end
24
+
25
+ # Custom getter for the creator of the campaign.
26
+ # @return [Arkaan::Account] the account of the player that created this file.
27
+ def creator
28
+ return permissions.where(enum_level: :creator).first.invitation.account
29
+ end
30
+
31
+ # Checks if an account is allowed to access this file, accounts must have one of the following characteristics to read a file :
32
+ # - Be the creator of the file
33
+ # - Be the game master of the campaign in which the file is declared
34
+ # - Have been granted the permission to access the file
35
+ #
36
+ # @param account [Arkaan::Account] the account trying to access the file.
37
+ # @return [Boolean] TRUE if this account has the right to access the file, FALSe otherwise.
38
+ def is_allowed?(account)
39
+ return true if campaign.creator.id == account.id
40
+ return true if creator.id == account.id
41
+ return true if has_permission?(account)
42
+ return false
43
+ end
44
+
45
+ # Checks if the account has the permission to access the designated file.
46
+ # @param account [Arkaan::Account] the account to check the existence of a permission for.
47
+ # @return [Boolean] TRUE if the account has a permission to access this file, FALSE otherwise.
48
+ def has_permission?(account)
49
+ invitation = campaign.invitations.where(account: account).first
50
+ return !invitation.nil? && permissions.where(invitation: invitation).exists?
51
+ end
52
+ end
53
+ end
54
+ end
@@ -2,9 +2,7 @@ module Arkaan
2
2
  module Campaigns
3
3
  # Representation of a file, allowing us to retrieve it on AWS by its filename and linked campaign ID.
4
4
  # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- class File
6
- include Mongoid::Document
7
- include Mongoid::Timestamps
5
+ class File < Arkaan::Campaigns::Document
8
6
  include Arkaan::Concerns::MimeTypable
9
7
 
10
8
  # @!attribute [rw] filename
@@ -16,11 +14,7 @@ module Arkaan
16
14
 
17
15
  mime_type ['image/*', 'text/plain']
18
16
 
19
- # @!attribute [rw] invitation
20
- # @return [Arkaan::Campaigns::Invitation] the link to the user creator of the file and the campaign it's created in.
21
- embedded_in :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :files
22
-
23
- validates :name , presence: {message: 'required'}
17
+ validates :name, presence: {message: 'required'}
24
18
  end
25
19
  end
26
20
  end
@@ -0,0 +1,7 @@
1
+ module Arkaan
2
+ module Campaigns
3
+ module Files
4
+ autoload :Permission, 'arkaan/campaigns/files/permission'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ module Arkaan
2
+ module Campaigns
3
+ module Files
4
+ # A file permission is the permission given by the creator of the file to another player to access it.
5
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
6
+ class Permission
7
+ include Mongoid::Document
8
+ include Mongoid::Timestamps
9
+ include Arkaan::Concerns::Enumerable
10
+
11
+ # The status of a permission just differenciates the creator and the other players for the moment
12
+ # But it will later be used to give different access rights like read/write
13
+ # @!attribute [rw] status
14
+ # @return [Symbol] the current level of permission for the linked user on the linked file.
15
+ enum_field :level, [:creator, :read], default: :read
16
+
17
+ # @!attribute [rw] invitation
18
+ # @return [Arkaan::Campaigns::Invitation] the invitation of the player in the campaign where this file was uploaded.
19
+ belongs_to :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :permissions
20
+ # @!attribute [rw] file
21
+ # @return [Arkaan::Campaigns::File] the file on which the permissions are granted.
22
+ belongs_to :file, class_name: 'Arkaan::Campaigns::File', inverse_of: :permissions
23
+ end
24
+ end
25
+ end
26
+ end
@@ -20,7 +20,7 @@ module Arkaan
20
20
 
21
21
  # @!attribute [rw] files
22
22
  # @return [Array<Arkaan::Campaigns::File>] the files uploaded in this campaign by the usere linked to this invitation.
23
- embeds_many :files, class_name: 'Arkaan::Campaigns::File', inverse_of: :invitation
23
+ has_many :permissions, class_name: 'Arkaan::Campaigns::File', inverse_of: :invitation
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,7 @@
1
+ module Arkaan
2
+ module Campaigns
3
+ class Note < Arkaan::Campaigns::Document
4
+ field :content, type: String, default: ''
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ module Arkaan
2
+ # A notification is a little something to warn a user that an action concerning him or her occurred.
3
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
4
+ class Notification
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ # @!attribute [rw] type
9
+ # @return [String] the type of notification this is supposed to be. All types are custom and facultative.
10
+ field :type, type: String, default: 'NOTIFICATIONS.DEFAULT'
11
+ # @!attribute [rw] read
12
+ # @return [Boolean] TRUE if the notification has been read (seen by the user), FALSE otherwise.
13
+ field :read, type: Boolean, default: false
14
+ # @!attribute [rw] data
15
+ # @return [Hash] the custom data that can be attached to this notification, for example for an invitation it can be the invited username.
16
+ field :data, type: Hash, default: {}
17
+
18
+ # @!attribute [rw] account
19
+ # @return [Arkaan::Account] the account concerned by this notification.
20
+ embedded_in :account, class_name: 'Arkaan::Account', inverse_of: :notifications
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module Arkaan
2
+ # A set of rules is describing how a specific game system works (eg. Dungeons and Dragons 5th Edition, or Fate)
3
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
4
+ class Ruleset
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ # @!attribute [rw] name
9
+ # @return [String] the name of the ruleset (eq. "Dungeons and Dragons 4th Edition")
10
+ field :name, type: String
11
+ # @!attribute [rw] description
12
+ # @return [String] the complete description of the rule set to quickly have informations on its content.
13
+ field :description, type: String
14
+
15
+ # @!attribute [rw] creator
16
+ # @return [Arkaan::Account] the account of the user creating this ruleset.
17
+ belongs_to :creator, class_name: 'Arkaan::Account', inverse_of: :rulesets
18
+ # @!attribute [rw] blueprints
19
+ # @return [Array<Arkaan::Rulesets::Blueprint>] the blueprints created inside this ruleset, see the class itself to know what it is.
20
+ has_many :blueprints, class_name: 'Arkaan::Rulesets::Blueprint', inverse_of: :ruleset
21
+
22
+ validates :name,
23
+ presence: {message: 'required'},
24
+ length: {minimum: 4, message: 'minlength', if: :name?},
25
+ uniqueness: {message: 'uniq', if: :name?}
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Arkaan
2
+ # The rulesets module holds all the logic for components present inside a ruleset.
3
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
4
+ module Rulesets
5
+ autoload :Blueprint, 'arkaan/rulesets/blueprint'
6
+ autoload :Field , 'arkaan/rulesets/field'
7
+ autoload :Fields , 'arkaan/rulesets/fields'
8
+ autoload :Gauge , 'arkaan/rulesets/gauge'
9
+ autoload :Integer , 'arkaan/rulesets/integer'
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ module Arkaan
2
+ module Rulesets
3
+ # A blueprint defines what a type of entity contains.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class Blueprint
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ # @!attribute [rw] name
10
+ # @return [String] the name of this type of entity in the ruleset.
11
+ field :name, type: String
12
+
13
+ # @!attribute [rw] ruleset
14
+ # @return [Arkaan::Ruleset] the ruleset to which this blueprint belongs.
15
+ belongs_to :ruleset, class_name: 'Arkaan::Ruleset', inverse_of: :blueprints
16
+ # @!attribute [rw] _fields
17
+ # @return [Array<Arkaan::Rulesets::Field>] the field composing the attributes of this blueprint.
18
+ embeds_many :_fields, class_name: 'Arkaan::Rulesets::Field', inverse_of: :blueprint
19
+
20
+ validates :name,
21
+ presence: {message: 'required'},
22
+ length: {minimum: 4, message: 'minlength', if: :name?}
23
+
24
+ validate :name_unicity
25
+
26
+ def name_unicity
27
+ has_duplicate = ruleset.blueprints.where(:_id.ne => _id, name: name).exists?
28
+ if !ruleset.nil? && name? && has_duplicate
29
+ errors.add(:name, 'uniq')
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,71 @@
1
+ module Arkaan
2
+ module Rulesets
3
+ # A field is an attribute of a blueprint, with a type and a name.
4
+ # It does not have a defined value as it will be given in the instance of the blueprint.
5
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
6
+ class Field
7
+ include Mongoid::Document
8
+ include Mongoid::Timestamps
9
+ include Arkaan::Concerns::Enumerable
10
+
11
+ # @!attribute [rw] name
12
+ # @return [String] the name of the field is comparable to the name of a variable.
13
+ field :name, type: String
14
+ # @!attribute [rw] data
15
+ # @return [Hash] the additional data, mainly constraints and needed values, for the field.
16
+ field :data, type: Hash, default: {}
17
+
18
+ # @!attribute [rw] blueprint
19
+ # @return [Arkaan::Rulesets::Blueprint] the blueprint in which the field belongs.
20
+ embedded_in :blueprint, class_name: 'Arkaan::Rulesets::Blueprint', inverse_of: :_fields
21
+
22
+ validates :name,
23
+ presence: {message: 'required'},
24
+ length: {minimum: 4, message: 'minlength', if: :name?},
25
+ format: {with: /\A[a-zA-Z_]*\z/, message: 'pattern', if: :name?}
26
+
27
+ validate :name_unicity
28
+
29
+ validate :options_validity
30
+
31
+ # Getter for the type of the field, returning simply the last element of the type for simpler use.
32
+ # @return [Symbol] the name of the type of the field (eq :Integer or :Gauge)
33
+ def type
34
+ return _type.split('::').last.to_sym
35
+ end
36
+
37
+ # Default options for this type of field, specialize it in the subclasses.
38
+ # @return [Hash] a hash with the default value for all options you want default values on.
39
+ def default_options
40
+ return {}
41
+ end
42
+
43
+ # Setter for the additional datas, merging it with the default options for the current type.
44
+ # @param new_data [Hash] the additional data to add to this field.
45
+ def data=(new_data)
46
+ self[:data] = default_options.merge(new_data)
47
+ end
48
+
49
+ def name_unicity
50
+ has_duplicate = blueprint._fields.where(:_id.ne => _id, name: name).exists?
51
+ if name? && blueprint && has_duplicate
52
+ errors.add(:name, 'uniq')
53
+ end
54
+ end
55
+
56
+ def options_validity
57
+ send(:validate_options) rescue true
58
+ end
59
+
60
+ # Checks the corresponding option key against the given data type. All types can be used.
61
+ # @param key [String] the name of the key in the options you want to check the type of.
62
+ # @param required_type [String] the exact name of the class you want to check the option against.
63
+ def check_type(key, required_type)
64
+ parsed_type = Object.const_get("::#{required_type}")
65
+ if !errors.messages.has_key?(:data) && data[key.to_sym] && !data[key.to_sym].is_a?(parsed_type)
66
+ errors.add(:data, "#{key.to_s}|type")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,10 @@
1
+ module Arkaan
2
+ module Rulesets
3
+ # This module holds all the classes for the different fields types in the blueprints.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ module Fields
6
+ autoload :Gauge , 'arkaan/rulesets/fields/gauge'
7
+ autoload :Integer, 'arkaan/rulesets/fields/integer'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Arkaan
2
+ module Rulesets
3
+ module Fields
4
+ # A gauge is composed of a max value, and a min value, and when instanciated has a current value that can't go above max or below min.
5
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
6
+ class Gauge < Arkaan::Rulesets::Field
7
+ def default_options
8
+ return {initial: 0, max: 100, min: 0, show: true}
9
+ end
10
+
11
+ def validate_options
12
+ check_type(:initial, 'Integer')
13
+ check_type(:max, 'Integer')
14
+ check_type(:min, 'Integer')
15
+ check_type(:show, 'Boolean')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ module Arkaan
2
+ module Rulesets
3
+ module Fields
4
+ # An integer field can have a minimum and maximum value.
5
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
6
+ class Integer < Arkaan::Rulesets::Field
7
+ def validate_options
8
+ check_type(:max, 'Integer')
9
+ check_type(:min, 'Integer')
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
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.3.11
4
+ version: 1.4.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-12-10 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.11.1
125
- - !ruby/object:Gem::Dependency
126
- name: draper
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '='
130
- - !ruby/object:Gem::Version
131
- version: 3.0.1
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '='
137
- - !ruby/object:Gem::Version
138
- version: 3.0.1
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: mongoid
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -248,6 +234,20 @@ dependencies:
248
234
  - - '='
249
235
  - !ruby/object:Gem::Version
250
236
  version: 0.15.2
237
+ - !ruby/object:Gem::Dependency
238
+ name: draper
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - '='
242
+ - !ruby/object:Gem::Version
243
+ version: 3.0.1
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - '='
249
+ - !ruby/object:Gem::Version
250
+ version: 3.0.1
251
251
  description: This gem holds the model layer for my table-top RPG games application.
252
252
  email: courtois.vincent@outlook.com
253
253
  executables: []
@@ -260,9 +260,13 @@ files:
260
260
  - lib/arkaan/authentication/session.rb
261
261
  - lib/arkaan/campaign.rb
262
262
  - lib/arkaan/campaigns.rb
263
+ - lib/arkaan/campaigns/document.rb
263
264
  - lib/arkaan/campaigns/file.rb
265
+ - lib/arkaan/campaigns/files.rb
266
+ - lib/arkaan/campaigns/files/permission.rb
264
267
  - lib/arkaan/campaigns/invitation.rb
265
268
  - lib/arkaan/campaigns/message.rb
269
+ - lib/arkaan/campaigns/note.rb
266
270
  - lib/arkaan/campaigns/tag.rb
267
271
  - lib/arkaan/concerns.rb
268
272
  - lib/arkaan/concerns/activable.rb
@@ -287,6 +291,7 @@ files:
287
291
  - lib/arkaan/monitoring/route.rb
288
292
  - lib/arkaan/monitoring/service.rb
289
293
  - lib/arkaan/monitoring/websocket.rb
294
+ - lib/arkaan/notification.rb
290
295
  - lib/arkaan/oauth.rb
291
296
  - lib/arkaan/oauth/access_token.rb
292
297
  - lib/arkaan/oauth/application.rb
@@ -297,6 +302,13 @@ files:
297
302
  - lib/arkaan/permissions/group.rb
298
303
  - lib/arkaan/permissions/right.rb
299
304
  - lib/arkaan/phone.rb
305
+ - lib/arkaan/ruleset.rb
306
+ - lib/arkaan/rulesets.rb
307
+ - lib/arkaan/rulesets/blueprint.rb
308
+ - lib/arkaan/rulesets/field.rb
309
+ - lib/arkaan/rulesets/fields.rb
310
+ - lib/arkaan/rulesets/fields/gauge.rb
311
+ - lib/arkaan/rulesets/fields/integer.rb
300
312
  - lib/arkaan/specs.rb
301
313
  - lib/arkaan/utils.rb
302
314
  - lib/arkaan/utils/controller.rb