lib/publishus.rb in publishus-0.0.2 vs lib/publishus.rb in publishus-0.0.3
- old
+ new
@@ -15,20 +15,19 @@
end
module ClassMethods
def publishable
-
versioned
named_scope :published, :conditions => "#{name.tableize}.published_at is not null and (#{name.tableize}.deleted_at < #{name.tableize}.published_at or #{name.tableize}.deleted_at is null)" do
def live
collect do |publishable|
publishable.live
end
end
end
-
+ before_destroy :choose_fait
include InstanceMethods
end
end
@@ -42,14 +41,17 @@
returning self do |publishable|
publishable.revert_to(publishable.published_at) unless publishable.current?
end
end
- def destroy(real=false)
- self.update_attribute(:deleted_at, Time.now)
+ attr_accessor :proper_destroy
+
+ def real_destroy
+ @proper_destroy = true
+ destroy
end
-
+
def publish!(time=nil)
self.update_attribute(:published_at, time||Time.now)
end
def publish_all!
@@ -58,9 +60,18 @@
end
def published?
!self.published_at.nil?
end
+
+ private
+
+ def choose_fait
+ unless @proper_destroy
+ self.update_attribute(:deleted_at, Time.now)
+ false
+ end
+ end
end
end
ActiveRecord::Base.send(:include, Publishus)
\ No newline at end of file