Class: TradeShow
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- TradeShow
- Includes:
- Models::Auditable
- Defined in:
- app/models/trade_show.rb
Overview
== Schema Information
Table name: trade_shows
Database name: primary
id :bigint not null, primary key
booth :string
end_date :date not null
location :string
name :string not null
staff :string
start_date :date not null
created_at :datetime not null
updated_at :datetime not null
logo_id :bigint
Indexes
index_trade_shows_on_logo_id (logo_id)
Foreign Keys
fk_rails_... (logo_id => digital_assets.id)
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #end_date ⇒ Object readonly
-
#name ⇒ Object
readonly
Validations.
- #start_date ⇒ Object readonly
Belongs to collapse
-
#logo ⇒ Image
Associations.
Methods included from Models::Auditable
Class Method Summary collapse
-
.by_year ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are by year.
-
.chronological ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are chronological.
-
.past ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are past.
- .ransackable_associations(_auth_object = nil) ⇒ Object
-
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration.
-
.reverse_chronological ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are reverse chronological.
-
.upcoming ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are upcoming.
Instance Method Summary collapse
- #date_range_display ⇒ Object
- #past? ⇒ Boolean
- #short_date_range ⇒ Object
- #single_day? ⇒ Boolean
-
#upcoming? ⇒ Boolean
Helper methods.
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#end_date ⇒ Object (readonly)
86 |
# File 'app/models/trade_show.rb', line 86 validates :end_date, presence: true |
#name ⇒ Object (readonly)
Validations
Validations:
84 |
# File 'app/models/trade_show.rb', line 84 validates :name, presence: true |
#start_date ⇒ Object (readonly)
85 |
# File 'app/models/trade_show.rb', line 85 validates :start_date, presence: true |
Class Method Details
.by_year ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are by year. Active Record Scope
92 |
# File 'app/models/trade_show.rb', line 92 scope :by_year, ->(year) { where('EXTRACT(YEAR FROM start_date) = ?', year) } |
.chronological ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are chronological. Active Record Scope
93 |
# File 'app/models/trade_show.rb', line 93 scope :chronological, -> { order(start_date: :asc) } |
.past ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are past. Active Record Scope
91 |
# File 'app/models/trade_show.rb', line 91 scope :past, -> { where(end_date: ...Date.current).order(start_date: :desc) } |
.ransackable_associations(_auth_object = nil) ⇒ Object
101 102 103 |
# File 'app/models/trade_show.rb', line 101 def self.ransackable_associations(_auth_object = nil) %w[logo] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration
97 98 99 |
# File 'app/models/trade_show.rb', line 97 def self.ransackable_attributes(_auth_object = nil) %w[name location start_date end_date booth staff created_at updated_at] end |
.reverse_chronological ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are reverse chronological. Active Record Scope
94 |
# File 'app/models/trade_show.rb', line 94 scope :reverse_chronological, -> { order(start_date: :desc) } |
.upcoming ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are upcoming. Active Record Scope
90 |
# File 'app/models/trade_show.rb', line 90 scope :upcoming, -> { where(end_date: Date.current..).order(start_date: :asc) } |
Instance Method Details
#date_range_display ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/models/trade_show.rb', line 118 def date_range_display if single_day? start_date.strftime('%b %-d, %Y') elsif start_date.year == end_date.year && start_date.month == end_date.month "#{start_date.strftime('%b %-d')} - #{end_date.strftime('%-d, %Y')}" elsif start_date.year == end_date.year "#{start_date.strftime('%b %-d')} - #{end_date.strftime('%b %-d, %Y')}" else "#{start_date.strftime('%b %-d, %Y')} - #{end_date.strftime('%b %-d, %Y')}" end end |
#logo ⇒ Image
Associations
81 |
# File 'app/models/trade_show.rb', line 81 belongs_to :logo, class_name: 'Image', optional: true |
#past? ⇒ Boolean
110 111 112 |
# File 'app/models/trade_show.rb', line 110 def past? end_date < Date.current end |
#short_date_range ⇒ Object
130 131 132 133 134 135 136 |
# File 'app/models/trade_show.rb', line 130 def short_date_range if single_day? start_date.strftime('%b %-d') else "#{start_date.strftime('%b %-d')} - #{end_date.strftime('%b %-d')}" end end |
#single_day? ⇒ Boolean
114 115 116 |
# File 'app/models/trade_show.rb', line 114 def single_day? start_date == end_date end |
#upcoming? ⇒ Boolean
Helper methods
106 107 108 |
# File 'app/models/trade_show.rb', line 106 def upcoming? end_date >= Date.current end |