Class: Arkaan::Campaign

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/arkaan/campaign.rb

Overview

A campaign is a gathering of accounts playing on the same interface, and interacting in a common game.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionString

Returns a more detailed description, used to give further information about the campaign in general.

Returns:

  • (String)

    a more detailed description, used to give further information about the campaign in general.



13
# File 'lib/arkaan/campaign.rb', line 13

field :description, type: String

#invitationsArray<Arkaan::Campaigns::Invitation>

Returns the invitations to players that have been made for this campaign.

Returns:



26
# File 'lib/arkaan/campaign.rb', line 26

has_many :invitations, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :campaign

#is_privateBoolean

Returns TRUE if the campaign can be joined only by being invited by the creator, FALSE if it’s publicly displayed and accessible.

Returns:

  • (Boolean)

    TRUE if the campaign can be joined only by being invited by the creator, FALSE if it’s publicly displayed and accessible.



16
# File 'lib/arkaan/campaign.rb', line 16

field :is_private, type: Boolean, default: true

#messagesArray<Arkaan::Campaigns::Messages::Base>

Returns the messages sent in the chatroom of the campaign.

Returns:



30
# File 'lib/arkaan/campaign.rb', line 30

embeds_many :messages, class_name: 'Arkaan::Campaigns::Messages::Base', inverse_of: :campaign

#tagsArray<String>

Returns an array of tags describing characteristics of this campaign.

Returns:

  • (Array<String>)

    an array of tags describing characteristics of this campaign.



19
# File 'lib/arkaan/campaign.rb', line 19

field :tags, type: Array, default: []

#titleString

Returns the title, or name, of the campaign, used to identify it in the list.

Returns:

  • (String)

    the title, or name, of the campaign, used to identify it in the list.



10
# File 'lib/arkaan/campaign.rb', line 10

field :title, type: String

Instance Method Details

#creatorArkaan::Account

Getter for the creator account of this campaign.

Returns:



48
49
50
# File 'lib/arkaan/campaign.rb', line 48

def creator
  return invitations.where(enum_status: :creator).first.
end

#creator=(account) ⇒ Object

Sets the creator of the campaign. This method is mainly used for backward-compatibility needs.

Parameters:

  • account (Arkaan::Account)

    the account of the creator for this campaign.



40
41
42
43
44
# File 'lib/arkaan/campaign.rb', line 40

def creator=()
  if !invitations.where(account: ).exists?
    Arkaan::Campaigns::Invitation.create(campaign: self, account: , enum_status: :creator)
  end
end

#title_unicityObject

Adds an error message if the account creating this campaign already has a campaign with the very same name.



53
54
55
56
57
58
59
60
61
# File 'lib/arkaan/campaign.rb', line 53

def title_unicity
  # First we take all the other campaign ids of the user.
  campaign_ids = creator.invitations.where(:campaign_id.ne => _id).pluck(:campaign_id)
  # With this list of campaign IDs, we look for a campaign with the same title.
  same_title_campaign = Arkaan::Campaign.where(:_id.in => campaign_ids, title: title)
  if !creator.nil? && title? && same_title_campaign.exists?
    errors.add(:title, 'uniq')
  end
end