Sha256: 1208b182fde9b0b830fde21170f993bd3571749a8153b51a25a8543dc3552eb2

Contents?: true

Size: 991 Bytes

Versions: 3

Compression:

Stored size: 991 Bytes

Contents

module ChosenTemplate
  module Chosen

    extend ActiveSupport::Concern

    included do
      scope :published_templates, -> {
        where("#{self.table_name}.template_published_at IS NOT NULL")
      }
      scope :by_template_published_at, -> {
        published_templates.order("#{self.table_name}.template_published_at DESC")
      }
      scope :previewed_templates, -> {
        where("#{self.table_name}.template_previewed_at IS NOT NULL")
      }
      scope :by_template_previewed_at, -> {
        previewed_templates.order("#{self.table_name}.template_previewed_at DESC")
      }
    end

    def previewed_template?
      self.class.by_template_previewed_at.first == self
    end

    def preview_template!
      self.update_attributes template_previewed_at: Time.now
    end

    def published_template?
      self.class.by_template_published_at.first == self
    end

    def publish_template!
      self.update_attributes template_published_at: Time.now
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chosen_template-1.0.0 lib/chosen_template/chosen.rb
chosen_template-0.1.0 lib/chosen_template/chosen.rb
chosen_template-0.0.1 lib/chosen_template/chosen.rb