Sha256: cb9351d14f5bc7478922d6c9ac69111c1c176400c4e9f619d913d40998d64cf0
Contents?: true
Size: 1.07 KB
Versions: 2
Compression:
Stored size: 1.07 KB
Contents
module PushType module Publishable extend ActiveSupport::Concern included do enum status: [ :draft, :published ] scope :published, -> { not_trash.where(['push_type_nodes.status = ? AND push_type_nodes.published_at <= ?', self.statuses[:published], Time.zone.now]). where(['push_type_nodes.published_to IS NULL OR push_type_nodes.published_to > ?', Time.zone.now]) } after_initialize :set_default_status before_save :set_published_at def published? super and !scheduled? and !expired? end end def scheduled? published_at? and published_at > Time.zone.now end def expired? published_to? and published_to < Time.zone.now end private def set_published_at case status when 'draft', self.class.statuses[:draft] then self.published_at = nil when 'published', self.class.statuses[:published] then self.published_at ||= Time.zone.now end end def set_default_status self.status ||= self.class.statuses[:draft] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
push_type_core-0.1.1 | app/models/concerns/push_type/publishable.rb |
push_type_core-0.1.0 | app/models/concerns/push_type/publishable.rb |