class Purgatory
Public Class Methods
approved()
click to toggle source
# File lib/purgatory/purgatory.rb, line 20 def self.approved where ["approved_at IS NOT NULL"] end
pending()
click to toggle source
# File lib/purgatory/purgatory.rb, line 16 def self.pending where(approved_at: nil) end
pending_with_matching_soul(soul)
click to toggle source
# File lib/purgatory/purgatory.rb, line 65 def self.pending_with_matching_soul(soul) pending.where("soul_id IS NOT NULL AND soul_id = ? AND soul_type = ?", soul.id, soul.class.base_class.name) end
Public Instance Methods
approve!(approver = nil)
click to toggle source
# File lib/purgatory/purgatory.rb, line 46 def approve!(approver = nil) self.with_lock do return false if approved? success = soul_with_changes.save if performable_method.present? && success success = soul.send(performable_method[:method],*performable_method[:args]) end if success self.approver = approver self.approved_at = Time.now self.soul_id = soul.id save return true end false end end
approved?()
click to toggle source
# File lib/purgatory/purgatory.rb, line 24 def approved? approved_at.present? end
pending?()
click to toggle source
# File lib/purgatory/purgatory.rb, line 28 def pending? approved_at.nil? end
soul()
click to toggle source
Calls superclass method
# File lib/purgatory/purgatory.rb, line 32 def soul @soul ||= (super || (sti_class || soul_type).constantize.new) end
soul_with_changes()
click to toggle source
# File lib/purgatory/purgatory.rb, line 40 def soul_with_changes requested_changes.each{|k,v| soul.send(:write_attribute, k, v[1])} if requested_changes attr_accessor_fields.each{|k,v| soul.instance_variable_set(k, v)} if attr_accessor_fields soul end
sti_class()
click to toggle source
# File lib/purgatory/purgatory.rb, line 36 def sti_class requested_changes['type'].try(:last) end
Private Instance Methods
destroy_pending_with_same_soul()
click to toggle source
# File lib/purgatory/purgatory.rb, line 75 def destroy_pending_with_same_soul Purgatory.pending_with_matching_soul(soul).destroy_all end
store_changes()
click to toggle source
# File lib/purgatory/purgatory.rb, line 71 def store_changes self.requested_changes = soul.changes end