Class: Calagator::Event
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Calagator::Event
- Includes:
- ActiveModel::Serializers::Xml, DecodeHtmlEntitiesHack, DuplicateChecking
- Defined in:
- app/models/calagator/event.rb,
app/models/calagator/event/saver.rb,
app/models/calagator/event/browse.rb,
app/models/calagator/event/cloner.rb,
app/models/calagator/event/search.rb,
app/models/calagator/event/overview.rb,
app/models/calagator/event/ical_renderer.rb,
app/models/calagator/event/search_engine.rb,
app/models/calagator/event/search_engine/sql.rb,
app/models/calagator/event/search_engine/apache_sunspot.rb
Defined Under Namespace
Classes: Browse, Cloner, IcalRenderer, Overview, Saver, Search, SearchEngine
Constant Summary
Constants included from DuplicateChecking
DuplicateChecking::DEFAULT_SQUASH_METHOD, DuplicateChecking::DUPLICATE_CHECKING_IGNORES_ATTRIBUTES, DuplicateChecking::DUPLICATE_MARK_COLUMN
Class Method Summary collapse
- .search(query, opts = {}) ⇒ Object
-
.search_tag(tag, opts = {}) ⇒ Object
—[ Searching ]——————————————————-.
Instance Method Summary collapse
- #check_if_locked_before_destroy ⇒ Object
-
#current? ⇒ Boolean
—[ Date related ]—————————————————-.
- #duration ⇒ Object
-
#end_time=(value) ⇒ Object
Set the end_time to the given
value
, which could be a Time, Date, DateTime, String, Array of Strings, or nil. -
#lock_editing! ⇒ Object
—[ Lock toggling ]—————————————————.
- #old? ⇒ Boolean
- #ongoing? ⇒ Boolean
-
#start_time=(value) ⇒ Object
Set the start_time to the given
value
, which could be a Time, Date, DateTime, String, Array of Strings, or nil. - #unlock_editing! ⇒ Object
-
#url=(value) ⇒ Object
—[ Overrides ]——————————————————-.
Methods included from DuplicateChecking
#duplicate?, #find_exact_duplicates, included, #originator, #primary?
Methods included from DecodeHtmlEntitiesHack
#decode_html_entities, included
Class Method Details
.search(query, opts = {}) ⇒ Object
160 161 162 |
# File 'app/models/calagator/event.rb', line 160 def self.search(query, opts = {}) SearchEngine.search(query, opts) end |
.search_tag(tag, opts = {}) ⇒ Object
—[ Searching ]——————————————————-
156 157 158 |
# File 'app/models/calagator/event.rb', line 156 def self.search_tag(tag, opts = {}) includes(:venue).tagged_with(tag).ordered_by_ui_field(opts[:order]) end |
Instance Method Details
#check_if_locked_before_destroy ⇒ Object
148 149 150 151 152 |
# File 'app/models/calagator/event.rb', line 148 def check_if_locked_before_destroy return if !locked errors.add :base, "Event must be unlocked before destroying" throw(:abort) end |
#current? ⇒ Boolean
—[ Date related ]—————————————————-
166 167 168 |
# File 'app/models/calagator/event.rb', line 166 def current? (end_time || start_time) >= Date.today.to_time end |
#duration ⇒ Object
180 181 182 183 184 |
# File 'app/models/calagator/event.rb', line 180 def duration return 0 unless end_time && start_time (end_time - start_time) end |
#end_time=(value) ⇒ Object
Set the end_time to the given value
, which could be a Time, Date, DateTime, String, Array of Strings, or nil.
122 123 124 125 126 127 |
# File 'app/models/calagator/event.rb', line 122 def end_time=(value) super time_for(value) rescue ArgumentError errors.add :end_time, 'is invalid' super nil end |
#lock_editing! ⇒ Object
—[ Lock toggling ]—————————————————
140 141 142 |
# File 'app/models/calagator/event.rb', line 140 def lock_editing! update_attribute(:locked, true) end |
#old? ⇒ Boolean
170 171 172 |
# File 'app/models/calagator/event.rb', line 170 def old? (end_time || start_time + 1.hour) <= Time.zone.now.beginning_of_day end |
#ongoing? ⇒ Boolean
174 175 176 177 178 |
# File 'app/models/calagator/event.rb', line 174 def ongoing? return unless end_time && start_time (start_time..end_time).cover?(Date.today.to_time) end |
#start_time=(value) ⇒ Object
Set the start_time to the given value
, which could be a Time, Date, DateTime, String, Array of Strings, or nil.
113 114 115 116 117 118 |
# File 'app/models/calagator/event.rb', line 113 def start_time=(value) super time_for(value) rescue ArgumentError errors.add :start_time, 'is invalid' super nil end |
#unlock_editing! ⇒ Object
144 145 146 |
# File 'app/models/calagator/event.rb', line 144 def unlock_editing! update_attribute(:locked, false) end |
#url=(value) ⇒ Object
—[ Overrides ]——————————————————-
107 108 109 |
# File 'app/models/calagator/event.rb', line 107 def url=(value) super UrlPrefixer.prefix(value) end |