Sha256: 11866baa0f866ca5ed096ac0c70d88aa005d4ff67c44ae45032fec781f494167
Contents?: true
Size: 1.05 KB
Versions: 22
Compression:
Stored size: 1.05 KB
Contents
require 'sequel' if $wikore_db == :memory DB = Sequel.sqlite else DB_FILE = __DIR__('wikore.db') DB = Sequel.connect("sqlite://#{DB_FILE}") end Sequel::Model.plugin :schema module Model PAGE_SCHEMA = lambda{ primary_key :id boolean :active, :default => true text :text integer :version } class Page < Sequel::Model(:page) set_schema do instance_eval(&PAGE_SCHEMA) text :title, :unique => true, :null => false end def backup hash = @values.dup hash.delete :id OldPage.create(hash) end def revert backup = OldPage[:title => title].values.dup backup.delete :id delete self.class.create(backup) end end class OldPage < Sequel::Model(:old_page) set_schema do instance_eval(&PAGE_SCHEMA) text :title, :unique => false, :null => false end end [Page, OldPage].each do |klass| begin klass.create_table rescue Sequel::DatabaseError => e if e.message !~ /table.*already exists/ raise e end end end end
Version data entries
22 entries across 22 versions & 4 rubygems
Version | Path |
---|---|
ramaze-2009.06.04 | examples/app/wikore/src/model.rb |
ramaze-2009.06 | examples/app/wikore/src/model.rb |