Sha256: 3c1d1035b6e1eaed854f85a16270128b027170c1fc92bc9f57e2e1e6f492068f

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

module Beef
  module Acts
    module Publishable
      module ClassMethods
        def acts_as_publishable
          send :include, InstanceMethods

          named_scope :published, lambda { { :conditions => ["(published_at IS NOT NULL AND published_at != '') AND published_at < ? AND (published_to > ? OR published_to IS NULL OR published_to = '')", Time.now, Time.now] } }

          before_save :set_published

          attr_accessor :publish, :hide
        end
      end

      module InstanceMethods

        def published?
          return false if published_at.nil?
          @published ||= published_at < Time.zone.now
        end

      private

        def set_published
          write_attribute :published_at, Time.zone.now if @publish and published_at.nil?
          if @hide    
            write_attribute :published_at, nil 
            write_attribute :published_to, nil 
          end
        end
      end

      def self.included(base)
        base.extend ClassMethods
      end
    end
  end  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
beef-acts_as_content_node-0.1.4 lib/acts_as_content_node/publishable.rb
beef-acts_as_content_node-0.1.5 lib/acts_as_content_node/publishable.rb