arkaan 1.7.0 → 1.8.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 +4 -4
- data/lib/arkaan/campaign.rb +6 -2
- data/lib/arkaan/campaigns.rb +0 -3
- data/lib/arkaan/campaigns/files.rb +5 -0
- data/lib/arkaan/campaigns/files/base.rb +56 -0
- data/lib/arkaan/campaigns/files/character.rb +48 -0
- data/lib/arkaan/campaigns/files/concerns.rb +9 -0
- data/lib/arkaan/campaigns/files/concerns/nameable.rb +64 -0
- data/lib/arkaan/campaigns/files/document.rb +18 -0
- data/lib/arkaan/campaigns/files/note.rb +9 -0
- data/lib/arkaan/campaigns/files/permission.rb +2 -2
- data/lib/arkaan/campaigns/invitation.rb +11 -2
- data/lib/arkaan/concerns/mime_typable.rb +7 -1
- data/lib/arkaan/ruleset.rb +10 -1
- data/lib/arkaan/rulesets.rb +2 -0
- data/lib/arkaan/rulesets/sheet.rb +28 -0
- data/lib/arkaan/rulesets/sheets.rb +10 -0
- data/lib/arkaan/rulesets/sheets/attribute.rb +40 -0
- data/lib/arkaan/rulesets/sheets/category.rb +25 -0
- data/lib/arkaan/version.rb +1 -1
- metadata +12 -5
- data/lib/arkaan/campaigns/document.rb +0 -54
- data/lib/arkaan/campaigns/file.rb +0 -65
- data/lib/arkaan/campaigns/note.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 931a5d11dc8f40aa987d3960f2a8e16dc66ec04c6f1a442ecc31f3bbc08431fa
|
4
|
+
data.tar.gz: a425f9550df833b6221daa379b57d1ecaa54d428a253de887dffc9845ba59d88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7263f342e7821a773574f5bdc98fa35e6d931bc1b2223941be1c5ac790dbf83d3063561ff82f4f0bf345e14ba30391ba22640225efe23e33b90b7bff04a8f0f
|
7
|
+
data.tar.gz: decf9dc3d4431fd1c8fd84f557dcb2f46ba8f7674add35b947ef167fb69cfc198fd1a1c0c47e8020d71b02f1e24d8b28ef721ecaad2accfd6428e1b00fbdac60
|
data/lib/arkaan/campaign.rb
CHANGED
@@ -25,13 +25,17 @@ module Arkaan
|
|
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
27
|
# @!attribute [rw] files
|
28
|
-
# @return [Array<Arkaan::Campaigns::
|
29
|
-
has_many :files, class_name: 'Arkaan::Campaigns::
|
28
|
+
# @return [Array<Arkaan::Campaigns::Files::Document>] the list of files that were uploaded in this campaign.
|
29
|
+
has_many :files, class_name: 'Arkaan::Campaigns::Files::Document', inverse_of: :campaign
|
30
30
|
|
31
31
|
# @!attribute [rw] messages
|
32
32
|
# @return [Array<Arkaan::Campaigns::Messages::Base>] the messages sent in the chatroom of the campaign.
|
33
33
|
embeds_many :messages, class_name: 'Arkaan::Campaigns::Message', inverse_of: :campaign
|
34
34
|
|
35
|
+
# @!attribute [rw] ruleset
|
36
|
+
# @return [Arkaan::Ruleset] the set of rules this campaign is based upon.
|
37
|
+
belongs_to :ruleset, class_name: 'Arkaan::Ruleset', inverse_of: :campaigns, optional: true
|
38
|
+
|
35
39
|
validates :title,
|
36
40
|
presence: {message: 'required'},
|
37
41
|
length: {minimum: 4, message: 'minlength', if: :title?}
|
data/lib/arkaan/campaigns.rb
CHANGED
@@ -2,12 +2,9 @@ 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'
|
6
|
-
autoload :File , 'arkaan/campaigns/file'
|
7
5
|
autoload :Files , 'arkaan/campaigns/files'
|
8
6
|
autoload :Invitation, 'arkaan/campaigns/invitation'
|
9
7
|
autoload :Message , 'arkaan/campaigns/message'
|
10
|
-
autoload :Note , 'arkaan/campaigns/note'
|
11
8
|
autoload :Tag , 'arkaan/campaigns/tag'
|
12
9
|
end
|
13
10
|
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module Arkaan
|
2
2
|
module Campaigns
|
3
3
|
module Files
|
4
|
+
autoload :Base , 'arkaan/campaigns/files/base'
|
5
|
+
autoload :Character , 'arkaan/campaigns/files/character'
|
6
|
+
autoload :Concerns , 'arkaan/campaigns/files/concerns'
|
7
|
+
autoload :Document , 'arkaan/campaigns/files/document'
|
8
|
+
autoload :Note , 'arkaan/campaigns/files/note'
|
4
9
|
autoload :Permission, 'arkaan/campaigns/files/permission'
|
5
10
|
end
|
6
11
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Campaigns
|
3
|
+
module Files
|
4
|
+
# 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.
|
5
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
+
class Base
|
7
|
+
include Mongoid::Document
|
8
|
+
include Mongoid::Timestamps
|
9
|
+
|
10
|
+
# @!attribute [rw] permission
|
11
|
+
# @return [Arkaan::Campaigns::Permission] the permissions granted to the different users of the campaign concerning this file.
|
12
|
+
has_many :permissions, class_name: 'Arkaan::Campaigns::Files::Permission', inverse_of: :file
|
13
|
+
|
14
|
+
# @!attribute [rw] campaign
|
15
|
+
# @return [Arkaan::Campaign] the campaign in which this file was uploaded.
|
16
|
+
belongs_to :campaign, class_name: 'Arkaan::Campaign', inverse_of: :files
|
17
|
+
|
18
|
+
# Custom setter for the creator of the file so that it can be used as a normal field.
|
19
|
+
# @param invitation [Arkaan::Campaigns::Invitation] the invitation of the player creating this file.
|
20
|
+
def creator=(invitation)
|
21
|
+
if !permissions.where(invitation: invitation).exists?
|
22
|
+
Arkaan::Campaigns::Files::Permission.create(enum_level: :creator, file: self, invitation: invitation)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Custom getter for the creator of the campaign.
|
27
|
+
# @return [Arkaan::Account] the account of the player that created this file.
|
28
|
+
def creator
|
29
|
+
return permissions.where(enum_level: :creator).first.invitation.account
|
30
|
+
end
|
31
|
+
|
32
|
+
# Checks if an account is allowed to access this file, accounts must have one of the following characteristics to read a file :
|
33
|
+
# - Be the creator of the file
|
34
|
+
# - Be the game master of the campaign in which the file is declared
|
35
|
+
# - Have been granted the permission to access the file
|
36
|
+
#
|
37
|
+
# @param account [Arkaan::Account] the account trying to access the file.
|
38
|
+
# @return [Boolean] TRUE if this account has the right to access the file, FALSe otherwise.
|
39
|
+
def is_allowed?(account)
|
40
|
+
return true if campaign.creator.id == account.id
|
41
|
+
return true if creator.id == account.id
|
42
|
+
return true if has_permission?(account)
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
# Checks if the account has the permission to access the designated file.
|
47
|
+
# @param account [Arkaan::Account] the account to check the existence of a permission for.
|
48
|
+
# @return [Boolean] TRUE if the account has a permission to access this file, FALSE otherwise.
|
49
|
+
def has_permission?(account)
|
50
|
+
invitation = campaign.invitations.where(account: account).first
|
51
|
+
return !invitation.nil? && permissions.where(invitation: invitation).exists?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Campaigns
|
3
|
+
module Files
|
4
|
+
# A character sheet represents a character played by a player in a campaign.
|
5
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
+
class Character < Arkaan::Campaigns::Files::Base
|
7
|
+
include Arkaan::Campaigns::Files::Concerns::Nameable
|
8
|
+
include Arkaan::Concerns::MimeTypable
|
9
|
+
|
10
|
+
# @!attribute [rw] selected
|
11
|
+
# @return [Boolean] TRUE if the sheet is currently selected by the player, FALSE otherwise.
|
12
|
+
field :selected, type: Boolean, default: false
|
13
|
+
# @!attribute [rw] mime_type
|
14
|
+
# @return [String] the mime_type of the character sheet, MUST be an authorized MIME type for
|
15
|
+
# the ruleset the campaign is set to be in.
|
16
|
+
mime_type :available_mime_types
|
17
|
+
|
18
|
+
# @!attribute [rw] invitation
|
19
|
+
# @return [Arkaan::Campaigns::Invitation] the invitation of the player playing this character.
|
20
|
+
belongs_to :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :characters
|
21
|
+
|
22
|
+
# Returns the player linked to this character.
|
23
|
+
# @return [Arkaan::Account] the account of the player incarnating this character.
|
24
|
+
def player
|
25
|
+
invitation.account
|
26
|
+
end
|
27
|
+
|
28
|
+
# Method used to dinamically determine what MIME types are allowed for this character sheet
|
29
|
+
# If the campaign this character is in has no ruleset, every MIME type is allowed.
|
30
|
+
# @return [Array<String>] the available MIME type for the campaign linked to this character.
|
31
|
+
def available_mime_types
|
32
|
+
invitation.campaign.ruleset.mime_types
|
33
|
+
end
|
34
|
+
|
35
|
+
# Puts the selected flag to TRUE for this character and to FALSE for all the
|
36
|
+
# other characters for the same player in the same campaign.
|
37
|
+
def select!
|
38
|
+
invitation.characters.each do |character|
|
39
|
+
character.update_attribute(:selected, false)
|
40
|
+
character.save!
|
41
|
+
end
|
42
|
+
update_attribute(:selected, true)
|
43
|
+
save!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Campaigns
|
3
|
+
module Files
|
4
|
+
module Concerns
|
5
|
+
module Nameable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
# @!attribute [rw] filename
|
10
|
+
# @return [String] the name of the file, corresponding to the AWS name.
|
11
|
+
field :name, type: String
|
12
|
+
|
13
|
+
validates :name, presence: {message: 'required'}
|
14
|
+
|
15
|
+
validate :name_unicity
|
16
|
+
|
17
|
+
# Checks if the name is unique in the campaign, and if it is not then modifies it.
|
18
|
+
# The modifications are the same than in a windows or UNIX system :
|
19
|
+
# - if the name exists as it is given, the system adds the suffix "(1)" to it.
|
20
|
+
# - if the name with the suffix still exists, the system tries to increment it until an available name is found.
|
21
|
+
# - the found name is then afected to the name of the current file.
|
22
|
+
def name_unicity
|
23
|
+
if !campaign.nil? && !self[:name].nil?
|
24
|
+
if exists_in_campaign(self[:name])
|
25
|
+
suffix = 1
|
26
|
+
while exists_in_campaign(merge_suffix(suffix))
|
27
|
+
suffix = suffix + 1
|
28
|
+
end
|
29
|
+
self[:name] = merge_suffix(suffix)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Merges the given suffix with the name correctly.
|
35
|
+
# @param suffix [String] the suffix to append between perenthesis at the end of the file name, but before the extension.
|
36
|
+
# @return [String] the complete name for the file, with the suffix correctly appended.
|
37
|
+
def merge_suffix(suffix)
|
38
|
+
return "#{raw_name} (#{suffix}).#{extension}"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Checks if the given name already exists for a file in the campaign.
|
42
|
+
# @param tmp_name [String] the name to check the existence of in the campaign.
|
43
|
+
# @return [Boolean] TRUE if the file exists in the campaign, FALSE otherwise.
|
44
|
+
def exists_in_campaign(tmp_name)
|
45
|
+
campaign.files.where(name: tmp_name, :id.ne => id).exists?
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the file name without the extension for the current file.
|
49
|
+
# @return [String] the name of the file without the extension.
|
50
|
+
def raw_name
|
51
|
+
return self[:name].gsub(".#{extension}", '')
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the extension of the file, without the dot.
|
55
|
+
# @return [String] the text representation for this file extension, without the leading dot.
|
56
|
+
def extension
|
57
|
+
return self[:name].split('.').last
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Campaigns
|
3
|
+
module Files
|
4
|
+
# Representation of a file, allowing us to retrieve it on AWS by its filename and linked campaign ID.
|
5
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
+
class Document < Arkaan::Campaigns::Files::Base
|
7
|
+
include Arkaan::Concerns::MimeTypable
|
8
|
+
include Arkaan::Campaigns::Files::Concerns::Nameable
|
9
|
+
|
10
|
+
# @!attribute [rw] size
|
11
|
+
# @return [Integer] the size of the file in bytes.
|
12
|
+
field :size, type: Integer, default: 0
|
13
|
+
|
14
|
+
mime_type ['image/*', 'text/plain']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -18,8 +18,8 @@ module Arkaan
|
|
18
18
|
# @return [Arkaan::Campaigns::Invitation] the invitation of the player in the campaign where this file was uploaded.
|
19
19
|
belongs_to :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :permissions
|
20
20
|
# @!attribute [rw] file
|
21
|
-
# @return [Arkaan::Campaigns::
|
22
|
-
belongs_to :file, class_name: 'Arkaan::Campaigns::
|
21
|
+
# @return [Arkaan::Campaigns::Files::Document] the file on which the permissions are granted.
|
22
|
+
belongs_to :file, class_name: 'Arkaan::Campaigns::Files::Document', inverse_of: :permissions
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -19,8 +19,17 @@ module Arkaan
|
|
19
19
|
belongs_to :campaign, class_name: 'Arkaan::Campaign', inverse_of: :invitations
|
20
20
|
|
21
21
|
# @!attribute [rw] files
|
22
|
-
# @return [Array<Arkaan::Campaigns::
|
23
|
-
has_many :permissions, class_name: 'Arkaan::Campaigns::
|
22
|
+
# @return [Array<Arkaan::Campaigns::Files::Document>] the files uploaded in this campaign by the user linked to this invitation.
|
23
|
+
has_many :permissions, class_name: 'Arkaan::Campaigns::Files::Document', inverse_of: :invitation
|
24
|
+
# @!attribute [rw] characters
|
25
|
+
# @return [Array<Arkaan::Campaigns::Files::Character>] the character sheets for this player.
|
26
|
+
has_many :characters, class_name: 'Arkaan::Campaigns::Files::Character', inverse_of: :invitation
|
27
|
+
|
28
|
+
# Gets the currently selected character in a convenient way.
|
29
|
+
# @return [Arkaan::Campaigns::Files::Character] the character currently selected by the player.
|
30
|
+
def character
|
31
|
+
characters.where(selected: true).first
|
32
|
+
end
|
24
33
|
end
|
25
34
|
end
|
26
35
|
end
|
@@ -23,7 +23,13 @@ module Arkaan
|
|
23
23
|
# Validates the validity of the MIME type by checking if it respects any of the given mime types.
|
24
24
|
# If it does not respect any MIME types possible, it adds an error to the mime_type field and invalidates.
|
25
25
|
define_method :mime_type_validity do
|
26
|
-
values.
|
26
|
+
checked_types = if values.is_a? Symbol
|
27
|
+
self.send(values) rescue []
|
28
|
+
else
|
29
|
+
values
|
30
|
+
end
|
31
|
+
return true if checked_types.empty?
|
32
|
+
checked_types.each do |type|
|
27
33
|
type_regex = ::Regexp.new("^#{type.sub(/\*/, '(.+)')}$")
|
28
34
|
return true if !type_regex.match(mime_type).nil?
|
29
35
|
end
|
data/lib/arkaan/ruleset.rb
CHANGED
@@ -11,13 +11,22 @@ module Arkaan
|
|
11
11
|
# @!attribute [rw] description
|
12
12
|
# @return [String] the complete description of the rule set to quickly have informations on its content.
|
13
13
|
field :description, type: String
|
14
|
+
# @!attribute [rw] mime_types
|
15
|
+
# @return [Array<String>] a list of MIME types accepted as character sheets MIME types.
|
16
|
+
field :mime_types, type: Array, default: []
|
14
17
|
|
15
18
|
# @!attribute [rw] creator
|
16
19
|
# @return [Arkaan::Account] the account of the user creating this ruleset.
|
17
20
|
belongs_to :creator, class_name: 'Arkaan::Account', inverse_of: :rulesets
|
18
21
|
# @!attribute [rw] blueprints
|
19
|
-
# @return [
|
22
|
+
# @return [Arr ay<Arkaan::Rulesets::Blueprint>] the blueprints created inside this ruleset, see the class itself to know what it is.
|
20
23
|
has_many :blueprints, class_name: 'Arkaan::Rulesets::Blueprint', inverse_of: :ruleset
|
24
|
+
# @!attribute [rw] campaigns
|
25
|
+
# @return [Array<Arkaan::Campaign>] the campaigns using this set of rules.
|
26
|
+
has_many :campaigns, class_name: 'Arkaan::Campaign', inverse_of: :ruleset
|
27
|
+
# @!attribute [rw] sheet
|
28
|
+
# @return [Arkaan::Rulesets::Sheet] the character sheet template for this set of rules.
|
29
|
+
has_one :sheet, class_name: 'Arkaan::Rulesets::Sheet', inverse_of: :ruleset
|
21
30
|
|
22
31
|
validates :name,
|
23
32
|
presence: {message: 'required'},
|
data/lib/arkaan/rulesets.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Rulesets
|
3
|
+
# A character sheet is the templating to parse and transform an uploaded
|
4
|
+
# XML file into a readable character sheet we can display on the interface.
|
5
|
+
# The main way to do it is to create attributes sorted into categories (optional)
|
6
|
+
# and to link each of these attributes to a XPath selector in the XML sheet
|
7
|
+
# the game master uploaded and linked to the player.
|
8
|
+
#
|
9
|
+
# This way we can just rebuild a JSON object with the categories and fields
|
10
|
+
# defined in the sheet, extracted from the XML sheet of the character.
|
11
|
+
#
|
12
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
13
|
+
class Sheet
|
14
|
+
include Mongoid::Document
|
15
|
+
include Mongoid::Timestamps
|
16
|
+
|
17
|
+
# @!attribute [rw] ruleset
|
18
|
+
# @return [Arkaan::Ruleset] the set of rules this sheet corresponds to.
|
19
|
+
belongs_to :ruleset, class_name: 'Arkaan::Ruleset', inverse_of: :sheet
|
20
|
+
# @!attribute [rw] creator
|
21
|
+
# @return [Arkaan::Account] the account of the creator of the sheet.
|
22
|
+
belongs_to :creator, class_name: 'Arkaan::Account'
|
23
|
+
# @!attribute [rw] categories
|
24
|
+
# @return [Array<Arkaan::Rulesets::Sheets::Category>] the categories declared in this sheet.
|
25
|
+
embeds_many :categories, class_name: 'Arkaan::Rulesets::Sheets::Category', inverse_of: :sheet
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Rulesets
|
3
|
+
# This module regroups the entities embedded in a character sheet template.
|
4
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
+
module Sheets
|
6
|
+
autoload :Attribute, 'arkaan/rulesets/sheets/attribute'
|
7
|
+
autoload :Category , 'arkaan/rulesets/sheets/category'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Rulesets
|
3
|
+
module Sheets
|
4
|
+
class Attribute
|
5
|
+
include Mongoid::Document
|
6
|
+
include Mongoid::Timestamps
|
7
|
+
include Arkaan::Concerns::Enumerable
|
8
|
+
|
9
|
+
# @!attribute [rw] name
|
10
|
+
# @return [String] the name of the attribute in the character sheet.
|
11
|
+
# This name is then used in the translation files as a key to retrieve it.
|
12
|
+
field :name, type: String, default: ''
|
13
|
+
# @!attribute [rw] default
|
14
|
+
# @return [Object] the default value for this attribute. Not typed so it
|
15
|
+
# can be any type of value (mainly integer, strings or datetimes)
|
16
|
+
field :default
|
17
|
+
# @!attribute [rw] xpath
|
18
|
+
# @return [String] the path to find this attribute in the XML sheet uploaded.
|
19
|
+
field :xpath, type: String
|
20
|
+
|
21
|
+
# @!attribute [rw] category
|
22
|
+
# @return [Arkaan::Rulesets::Sheets::Category] the category the attribute is in.
|
23
|
+
embedded_in :category, class_name: 'Arkaan::Rulesets::Sheets::Category', inverse_of: :attrs
|
24
|
+
|
25
|
+
validates :name,
|
26
|
+
presence: {message: 'required'},
|
27
|
+
format: {with: /\A[a-zA-Z_]*\z/, message: 'pattern', if: :name?}
|
28
|
+
|
29
|
+
validate :name_unicity
|
30
|
+
|
31
|
+
def name_unicity
|
32
|
+
has_duplicate = category.attrs.where(:_id.ne => _id, name: name).exists?
|
33
|
+
if name? && category && has_duplicate
|
34
|
+
errors.add(:name, 'uniq')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Rulesets
|
3
|
+
module Sheets
|
4
|
+
# A category is just a semantic group of attributes having the same function
|
5
|
+
# or sharing some semantic proximity (eg. all characteristics or skills).
|
6
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
7
|
+
class Category
|
8
|
+
include Mongoid::Document
|
9
|
+
include Mongoid::Timestamps
|
10
|
+
|
11
|
+
# @!attribute [rw] name
|
12
|
+
# @return [String] the name of the category you're creating.
|
13
|
+
field :name, type: String, default: ''
|
14
|
+
|
15
|
+
# @!attribute [rw] sheet
|
16
|
+
# @return [Arkaan::Rulesets::Sheet] the sheet template the category is embedded in;
|
17
|
+
embedded_in :sheet, class_name: 'Arkaan::Rulesets::Sheet', inverse_of: :categories
|
18
|
+
|
19
|
+
# @!attribute [rw] attributes
|
20
|
+
# @return [Array<Arkaan::Rulesets::Sheets::Attribute>] the attributes linked to this category.
|
21
|
+
embeds_many :attrs, class_name: 'Arkaan::Rulesets::Sheets::Attribute', inverse_of: :category
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/arkaan/version.rb
CHANGED
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.
|
4
|
+
version: 1.8.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: 2019-
|
11
|
+
date: 2019-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -302,13 +302,16 @@ files:
|
|
302
302
|
- lib/arkaan/authentication/session.rb
|
303
303
|
- lib/arkaan/campaign.rb
|
304
304
|
- lib/arkaan/campaigns.rb
|
305
|
-
- lib/arkaan/campaigns/document.rb
|
306
|
-
- lib/arkaan/campaigns/file.rb
|
307
305
|
- lib/arkaan/campaigns/files.rb
|
306
|
+
- lib/arkaan/campaigns/files/base.rb
|
307
|
+
- lib/arkaan/campaigns/files/character.rb
|
308
|
+
- lib/arkaan/campaigns/files/concerns.rb
|
309
|
+
- lib/arkaan/campaigns/files/concerns/nameable.rb
|
310
|
+
- lib/arkaan/campaigns/files/document.rb
|
311
|
+
- lib/arkaan/campaigns/files/note.rb
|
308
312
|
- lib/arkaan/campaigns/files/permission.rb
|
309
313
|
- lib/arkaan/campaigns/invitation.rb
|
310
314
|
- lib/arkaan/campaigns/message.rb
|
311
|
-
- lib/arkaan/campaigns/note.rb
|
312
315
|
- lib/arkaan/campaigns/tag.rb
|
313
316
|
- lib/arkaan/concerns.rb
|
314
317
|
- lib/arkaan/concerns/activable.rb
|
@@ -355,6 +358,10 @@ files:
|
|
355
358
|
- lib/arkaan/rulesets/fields.rb
|
356
359
|
- lib/arkaan/rulesets/fields/gauge.rb
|
357
360
|
- lib/arkaan/rulesets/fields/integer.rb
|
361
|
+
- lib/arkaan/rulesets/sheet.rb
|
362
|
+
- lib/arkaan/rulesets/sheets.rb
|
363
|
+
- lib/arkaan/rulesets/sheets/attribute.rb
|
364
|
+
- lib/arkaan/rulesets/sheets/category.rb
|
358
365
|
- lib/arkaan/specs.rb
|
359
366
|
- lib/arkaan/utils.rb
|
360
367
|
- lib/arkaan/utils/controllers.rb
|
@@ -1,54 +0,0 @@
|
|
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
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module Arkaan
|
2
|
-
module Campaigns
|
3
|
-
# Representation of a file, allowing us to retrieve it on AWS by its filename and linked campaign ID.
|
4
|
-
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
-
class File < Arkaan::Campaigns::Document
|
6
|
-
include Arkaan::Concerns::MimeTypable
|
7
|
-
|
8
|
-
# @!attribute [rw] filename
|
9
|
-
# @return [String] the name of the file, corresponding to the AWS name.
|
10
|
-
field :name, type: String
|
11
|
-
# @!attribute [rw] size
|
12
|
-
# @return [Integer] the size of the file in bytes.
|
13
|
-
field :size, type: Integer, default: 0
|
14
|
-
|
15
|
-
mime_type ['image/*', 'text/plain']
|
16
|
-
|
17
|
-
validates :name, presence: {message: 'required'}
|
18
|
-
|
19
|
-
validate :name_unicity
|
20
|
-
|
21
|
-
# Checks if the name is unique in the campaign, and if it is not then modifies it.
|
22
|
-
# The modifications are the same than in a windows or UNIX system :
|
23
|
-
# - if the name exists as it is given, the system adds the suffix "(1)" to it.
|
24
|
-
# - if the name with the suffix still exists, the system tries to increment it until an available name is found.
|
25
|
-
# - the found name is then afected to the name of the current file.
|
26
|
-
def name_unicity
|
27
|
-
if !campaign.nil? && !self[:name].nil?
|
28
|
-
if exists_in_campaign(self[:name])
|
29
|
-
suffix = 1
|
30
|
-
while exists_in_campaign(merge_suffix(suffix))
|
31
|
-
suffix = suffix + 1
|
32
|
-
end
|
33
|
-
self[:name] = merge_suffix(suffix)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Merges the given suffix with the name correctly.
|
39
|
-
# @param suffix [String] the suffix to append between perenthesis at the end of the file name, but before the extension.
|
40
|
-
# @return [String] the complete name for the file, with the suffix correctly appended.
|
41
|
-
def merge_suffix(suffix)
|
42
|
-
return "#{raw_name} (#{suffix}).#{extension}"
|
43
|
-
end
|
44
|
-
|
45
|
-
# Checks if the given name already exists for a file in the campaign.
|
46
|
-
# @param tmp_name [String] the name to check the existence of in the campaign.
|
47
|
-
# @return [Boolean] TRUE if the file exists in the campaign, FALSE otherwise.
|
48
|
-
def exists_in_campaign(tmp_name)
|
49
|
-
campaign.files.where(name: tmp_name, :id.ne => id).exists?
|
50
|
-
end
|
51
|
-
|
52
|
-
# Returns the file name without the extension for the current file.
|
53
|
-
# @return [String] the name of the file without the extension.
|
54
|
-
def raw_name
|
55
|
-
return self[:name].gsub(".#{extension}", '')
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns the extension of the file, without the dot.
|
59
|
-
# @return [String] the text representation for this file extension, without the leading dot.
|
60
|
-
def extension
|
61
|
-
return self[:name].split('.').last
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|