Module: Capcode

Defined in:
lib/capcode/base/sequel.rb

Defined Under Namespace

Modules: Resource Classes: Base

Class Method Summary collapse

Class Method Details

.dbObject



36
37
38
# File 'lib/capcode/base/sequel.rb', line 36

def db
  @db ||= Sequel.connect(@dbconfig)
end

.db_connect(dbfile, logfile) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/capcode/base/sequel.rb', line 40

def db_connect( dbfile, logfile )
  @dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
  @dbconfig[:adapter] = "sqlite" if @dbconfig[:adapter] == "sqlite3"
  version = @dbconfig.delete(:schema_version) { |_| @final }
  
  if @migrations
    Capcode::db.create_table? :schema_table do
      Float :version
    end
    si = Capcode::db[:schema_table].first || (Capcode::db[:schema_table].insert(:version => 0); {:version => 0})
    @migrations.each do |k|
      k.apply(Capcode::db, :up) if si[:version] < k.version and k.version <= version
      k.apply(Capcode::db, :down) if si[:version] >= k.version and k.version > version
    end
    Capcode::db[:schema_table].where(:version => si[:version]).update(:version => version)
  end
end

.Model(n) ⇒ Object

This class allow you to define models



27
28
29
30
31
32
33
34
# File 'lib/capcode/base/sequel.rb', line 27

def Model( n )
  @final = [n, @final.to_f].max
  m = (@migrations ||= [])
  Class.new(Sequel::Migration) do
    meta_def(:version) { n }
    meta_def(:inherited) { |k| m << k }
  end
end