Sha256: 90cc2d495592befd7d14d141798a7a6dc3a176a3a861bc8137b9209a973f99dd

Contents?: true

Size: 990 Bytes

Versions: 7

Compression:

Stored size: 990 Bytes

Contents

require 'sequel'

begin
  case $wikore_db
  when :memory
    DB = Sequel.sqlite
  else
    DB = Sequel.sqlite 'wikore.db'
  end
rescue NoMethodError
  raise LoadError, 'Install latest Sequel gem'
end

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|
    klass.create_table unless klass.table_exists?
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
clivecrous-ramaze-0.3.9.5 examples/wikore/src/model.rb
ramaze-0.3.0 examples/wikore/src/model.rb
ramaze-0.3.5 examples/wikore/src/model.rb
ramaze-0.2.1 examples/wikore/src/model.rb
ramaze-0.3.9 examples/wikore/src/model.rb
ramaze-0.3.9.1 examples/wikore/src/model.rb
ramaze-2008.06 examples/app/wikore/src/model.rb