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
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 Models::EventPublishable
Instance Attribute Details
#end_date ⇒ Object (readonly)
85 |
# File 'app/models/trade_show.rb', line 85 validates :end_date, presence: true |
#name ⇒ Object (readonly)
Validations
Validations:
83 |
# File 'app/models/trade_show.rb', line 83 validates :name, presence: true |
#start_date ⇒ Object (readonly)
84 |
# File 'app/models/trade_show.rb', line 84 validates :start_date, presence: true |
Class Method Details
.by_year ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are by year. Active Record Scope
91 |
# File 'app/models/trade_show.rb', line 91 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
92 |
# File 'app/models/trade_show.rb', line 92 scope :chronological, -> { order(start_date: :asc) } |
.past ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are past. Active Record Scope
90 |
# File 'app/models/trade_show.rb', line 90 scope :past, -> { where('end_date < ?', Date.current).order(start_date: :desc) } |
.ransackable_associations(_auth_object = nil) ⇒ Object
100 101 102 |
# File 'app/models/trade_show.rb', line 100 def self.ransackable_associations(_auth_object = nil) %w[logo] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration
96 97 98 |
# File 'app/models/trade_show.rb', line 96 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
93 |
# File 'app/models/trade_show.rb', line 93 scope :reverse_chronological, -> { order(start_date: :desc) } |
.upcoming ⇒ ActiveRecord::Relation<TradeShow>
A relation of TradeShows that are upcoming. Active Record Scope
89 |
# File 'app/models/trade_show.rb', line 89 scope :upcoming, -> { where('end_date >= ?', Date.current).order(start_date: :asc) } |
Instance Method Details
#date_range_display ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/models/trade_show.rb', line 117 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
80 |
# File 'app/models/trade_show.rb', line 80 belongs_to :logo, class_name: 'Image', optional: true |
#past? ⇒ Boolean
109 110 111 |
# File 'app/models/trade_show.rb', line 109 def past? end_date < Date.current end |
#short_date_range ⇒ Object
129 130 131 132 133 134 135 |
# File 'app/models/trade_show.rb', line 129 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
113 114 115 |
# File 'app/models/trade_show.rb', line 113 def single_day? start_date == end_date end |
#upcoming? ⇒ Boolean
Helper methods
105 106 107 |
# File 'app/models/trade_show.rb', line 105 def upcoming? end_date >= Date.current end |