Sha256: 7964f8ddd910854a429e1201f90128b14aaa942f78d06f2bd3666e1f1d2f323b
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
class Memento include Singleton class ErrorOnRewind < StandardError;end def memento(user) start(user) yield !@session.states.count.zero? && @session rescue false ensure stop end def start(user_or_id) user = User.find_by_id(user_or_id) @session = user ? Memento::Session.new(:user => user) : nil end def stop @session.destroy if @session && @session.states.count.zero? @session = nil end def add_state(action_type, record) return unless save_session @session.add_state(action_type, record) end def active? !!(defined?(@session) && @session) && !ignore? end def ignore @ignore = true yield ensure @ignore = false end private def ignore? defined?(@ignore) && @ignore end def save_session active? && (!@session.changed? || @session.save) end end require 'memento/result' require 'memento/action' require 'memento/active_record_methods' require 'memento/action_controller_methods' require 'memento/state' require 'memento/session'
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yolk-memento-0.2.0 | lib/memento.rb |