Class: Event

Inherits:
ApplicationRecord show all
Defined in:
app/models/event.rb

Overview

This model manage the events

Relations

has many Happening

Validates

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#created_atDateTime

Returns when the record was created.

Returns:

  • (DateTime)

    when the record was created



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#happenings_countInteger

Returns counter cache for Happening.

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#idInteger

Returns unique identifier for Fact.

Returns:

  • (Integer)

    unique identifier for Fact



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#pinnedBoolean

Returns [true] if this Fact has priority.

Returns:

  • (Boolean)
    true

    if this Fact has priority



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#start_ondate

Returns when start Fact.

Returns:

  • (date)

    when start Fact



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#stop_ondate

Returns when end Fact.

Returns:

  • (date)

    when end Fact



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#tickets_frequencyString

Returns enum of tickets frequency statuses.

Returns:

  • (String)

    enum of tickets frequency statuses



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#titleString

Returns title of Fact.

Returns:

  • (String)

    title of Fact



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#updated_atDateTime

Returns when the record was updated.

Returns:

  • (DateTime)

    when the record was updated



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

#wherestring

Returns where the Fact is located.

Returns:

  • (string)

    where the Fact is located



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

Class Method Details

.futureArray

Returns list of [Fact] with stop_on egual or greather than Time.zone.today, ordered by pinnes, stop_on.

Returns:

  • (Array)

    list of [Fact] with stop_on egual or greather than Time.zone.today, ordered by pinnes, stop_on



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

.historyArray

Returns list of [Fact] with stop_on minor than Time.zone.today, ordered by start_on desc.

Returns:

  • (Array)

    list of [Fact] with stop_on minor than Time.zone.today, ordered by start_on desc



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/event.rb', line 34

class Event < ApplicationRecord
  has_rich_text :body
  has_one_attached :image do |attachable|
    attachable.variant :card, resize_to_limit: [ 417, 278 ]
    attachable.variant :aside, resize_to_limit: [ 318, 318 ]
    attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
  end
  belongs_to :group
  has_many :happenings, dependent: :destroy
  has_many :tickets, through: :happenings
  validates :title, presence: true
  enum tickets_frequency: { any: 0, single: 1, daily: 2, weekly: 3, monthly: 4 }

  scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil) do
    by_keys = { stop_on: (from.try(:to_date) || Date.today).. }
    by_keys[:start_on] = ..to.try(:to_date) if to.present?
    by_keys[:group_id] = group_id  if group_id.present?
    by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil
    where(by_text).where(by_keys)
  end

  # @return {String} image path with variand or default image
  def image_url(_variant = :card)
    image.present? ? image.variant(:card) : "default.png"
  end
end

Instance Method Details

#image_url(_variant = :card) ⇒ String

Returns image path with variand or default image.

Returns:

  • (String)

    image path with variand or default image



56
57
58
# File 'app/models/event.rb', line 56

def image_url(_variant = :card)
  image.present? ? image.variant(:card) : "default.png"
end