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
Pistos-ramaze-2009.06.12 examples/app/wikore/src/model.rb
manveru-ramaze-2009.06.04 examples/app/wikore/src/model.rb
manveru-ramaze-2009.06.12 examples/app/wikore/src/model.rb
manveru-ramaze-2009.06 examples/app/wikore/src/model.rb
manveru-ramaze-2009.07 examples/app/wikore/src/model.rb
rjspotter-ramaze-2009.06.29 examples/app/wikore/src/model.rb
rjspotter-ramaze-2009.06.31 examples/app/wikore/src/model.rb
ramaze-2011.12.28 examples/app/wikore/src/model.rb
ramaze-2011.10.23 examples/app/wikore/src/model.rb
ramaze-2011.07.25 examples/app/wikore/src/model.rb
ramaze-2011.01.30 examples/app/wikore/src/model.rb
ramaze-2011.01 examples/app/wikore/src/model.rb
ramaze-2010.06.18 examples/app/wikore/src/model.rb
ramaze-2010.04.04 examples/app/wikore/src/model.rb
ramaze-2010.04 examples/app/wikore/src/model.rb
ramaze-2010.03 examples/app/wikore/src/model.rb
ramaze-2010.01 examples/app/wikore/src/model.rb
ramaze-2009.10 examples/app/wikore/src/model.rb
ramaze-2009.07 examples/app/wikore/src/model.rb
ramaze-2009.06.12 examples/app/wikore/src/model.rb