Sha256: c4dd4d59d3c32a797aa656d4423e13c8f62287c6e1bf1ce706613fc8f3cb460b

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 Bytes

Contents

require 'rubygems'
begin
  require 'dm-core'
  require 'dm-migrations'
rescue LoadError => e
  raise Capcode::MissingLibrary, "DataMapper could not be loaded (is it installed?): #{e.message}"
end
require 'yaml'
require 'logger'

module Capcode 
  Resource = DataMapper::Resource

  # use DataMapper
  # 
  # class Story < Capcode::Base
  #   include Capcode::Base
  #   property :id, Integer, :serial => true
  #   property :title, String
  #   property :body, String
  #   property :date, String
  # end  
  class Base
  end
  
  class << self
    def db_connect( dbfile, logfile ) #:nodoc:
      dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
      loglevel = (dbconfig.delete(:loglevel) || "error").to_sym
      DataMapper.finalize
      DataMapper::Logger.new(logfile, loglevel)
      DataMapper.setup(:default, dbconfig)
      DataMapper.auto_upgrade!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capcode-base-datamapper-0.3.0 lib/capcode/base/dm.rb