Class: PinnedLink
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PinnedLink
- Includes:
- MaybeCommunityRelated
- Defined in:
- /var/apps/qpixel/app/models/pinned_link.rb
Instance Method Summary collapse
- #check_period ⇒ Object
- #check_post_or_url ⇒ Object
-
#current?(now = DateTime.now) ⇒ Boolean
Is the link not timed or started in the past & hasn’t ended yet?.
-
#future?(now = DateTime.now) ⇒ Boolean
Does the link start in the future?.
-
#past?(now = DateTime.now) ⇒ Boolean
Has the link ended in the past?.
-
#timed? ⇒ Boolean
Is the link time-constrained?.
Methods inherited from ApplicationRecord
#attributes_print, fuzzy_search, match_search, #match_search, sanitize_for_search, sanitize_name, sanitize_sql_in, useful_err_msg, with_lax_group_rules
Instance Method Details
#check_period ⇒ Object
62 63 64 65 66 67 68 |
# File '/var/apps/qpixel/app/models/pinned_link.rb', line 62 def check_period return unless shown_before.present? && shown_after.present? if shown_before < shown_after errors.add(:base, 'end date cannot be earlier than the start date') end end |
#check_post_or_url ⇒ Object
70 71 72 73 74 |
# File '/var/apps/qpixel/app/models/pinned_link.rb', line 70 def check_post_or_url unless post_id.present? || link.present? errors.add(:base, 'either a post or a URL must be set') end end |
#current?(now = DateTime.now) ⇒ Boolean
Is the link not timed or started in the past & hasn’t ended yet?
38 39 40 |
# File '/var/apps/qpixel/app/models/pinned_link.rb', line 38 def current?(now = DateTime.now) !timed? || !(future?(now) || past?(now)) end |
#future?(now = DateTime.now) ⇒ Boolean
Does the link start in the future?
45 46 47 |
# File '/var/apps/qpixel/app/models/pinned_link.rb', line 45 def future?(now = DateTime.now) shown_after.present? && shown_after > now && (shown_before.nil? || shown_before >= now) end |
#past?(now = DateTime.now) ⇒ Boolean
Has the link ended in the past?
52 53 54 |
# File '/var/apps/qpixel/app/models/pinned_link.rb', line 52 def past?(now = DateTime.now) shown_before.present? && shown_before < now end |
#timed? ⇒ Boolean
Is the link time-constrained?
58 59 60 |
# File '/var/apps/qpixel/app/models/pinned_link.rb', line 58 def timed? shown_before.present? || shown_after.present? end |