Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add undo action (i.e. publish -> unpublish)

  • Loading branch information...
commit 9633c87c8edb6719fb1baddbe2ea082f15d13503 1 parent 89b28dc
@jamesgolick authored
Showing with 12 additions and 2 deletions.
  1. +12 −2 lib/timestamped_boolean.rb
View
14 lib/timestamped_boolean.rb
@@ -5,8 +5,9 @@ def self.included(base)
module ClassMethods
def timestamped_boolean(field_name, verb_name=nil)
- bool = field_name.to_s.sub(/_at$/, '')
- action = verb_name ? verb_name.to_s : bool.sub(/ed$/, '')
+ bool = field_name.to_s.sub(/_at$/, '')
+ action = verb_name ? verb_name.to_s : bool.sub(/ed$/, '')
+ undo_action = "un#{action}"
define_method(bool.to_sym) do
! send(field_name.to_sym).nil?
@@ -23,6 +24,15 @@ def timestamped_boolean(field_name, verb_name=nil)
send action.to_sym
send :save!
end
+
+ define_method(undo_action) do
+ send(field_name.to_s + '=', nil)
+ end
+
+ define_method(undo_action+'!') do
+ send(undo_action)
+ send :save!
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.