Class: Event
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Event
- Defined in:
- app/models/event.rb
Overview
Instance Attribute Summary collapse
-
#created_at ⇒ DateTime
When the record was created.
-
#happenings_count ⇒ Integer
Counter cache for Happening.
-
#id ⇒ Integer
Unique identifier for Fact.
-
#pinned ⇒ Boolean
- true
-
if this Fact has priority.
-
#start_on ⇒ date
When start Fact.
-
#stop_on ⇒ date
When end Fact.
-
#tickets_frequency ⇒ String
Enum of tickets frequency statuses.
-
#title ⇒ String
Title of Fact.
-
#updated_at ⇒ DateTime
When the record was updated.
-
#where ⇒ string
Where the Fact is located.
Class Method Summary collapse
-
.future ⇒ Array
List of [Fact] with stop_on egual or greather than Time.zone.today, ordered by pinnes, stop_on.
-
.history ⇒ Array
List of [Fact] with stop_on minor than Time.zone.today, ordered by start_on desc.
Instance Method Summary collapse
-
#image_url(_variant = :card) ⇒ String
Image path with variand or default image.
Instance Attribute Details
#created_at ⇒ DateTime
Returns 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_count ⇒ Integer
Returns counter cache for Happening.
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 |
#id ⇒ Integer
Returns 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 |
#pinned ⇒ Boolean
Returns [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_on ⇒ date
Returns 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_on ⇒ date
Returns 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_frequency ⇒ String
Returns 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 |
#title ⇒ String
Returns 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_at ⇒ DateTime
Returns 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 |
#where ⇒ string
Returns 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
.future ⇒ Array
Returns 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 |
.history ⇒ Array
Returns 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.
56 57 58 |
# File 'app/models/event.rb', line 56 def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end |