5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/acts_as_publishable/acts_as_publishable.rb', line 5
def acts_as_publishable(options = {})
metaclass = (class << self; self; end)
return if metaclass.included_modules.include?(ActsAsPublishable::InstanceMethods)
cattr_accessor :publish_now_column, :published_from_column, :published_to_column, :default_published_now
self.publish_now_column = options[:publish_now_column] || 'publish_now'
self.published_from_column = options[:published_from_column] || 'published_from'
self.published_to_column = options[:published_to_column] || 'published_to'
self.default_published_now = (options[:default_published_now] == true)
scope :published, where(["#{publish_now_column} = :published OR (#{published_from_column} <= :published_from AND #{published_to_column} >= :published_to)", {:published => true, :published_from => Time.now.utc, :published_to => Time.now.utc}])
before_save { |publishable| publishable[publish_now_column.to_sym] = default_published_now if publishable[publish_now_column.to_sym].nil?; true }
validate_chronology
send :include, ActsAsPublishable::InstanceMethods
end
|