Module: Schema

Extended by:
Schema
Included in:
Schema
Defined in:
app/models/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



21
22
23
# File 'app/models/schema.rb', line 21

def db
  @db
end

Instance Method Details

#config(env, file) ⇒ Object



17
18
19
# File 'app/models/schema.rb', line 17

def config(env,file)
  YAML::load(ERB.new(IO.read(file)).result)[env]
end

#connect(str) ⇒ Object



9
10
11
# File 'app/models/schema.rb', line 9

def connect(str)
  @db = Sequel.connect(str)
end

#create!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/schema.rb', line 26

def create!
  Sequel::MySQL.default_charset = 'utf8'
  Sequel::MySQL.default_engine = 'InnoDB'

  models.each { |model|
    model.create_table!
  }
  @db.create_table? :users_accounts do
    primary_key :id, :type=>Integer
    Fixnum :user_id, :null => false
    Fixnum :account_id, :null => false
  end
end

#current_connectObject



13
14
15
# File 'app/models/schema.rb', line 13

def current_connect
  @db
end

#drop!Object



40
41
42
43
44
# File 'app/models/schema.rb', line 40

def drop!
  models.each { |model|
    @db.drop_table(model.table_name)
  }
end

#modelsObject



46
47
48
49
50
# File 'app/models/schema.rb', line 46

def models
  @models ||= [Account, User,
               Authz,Tag,TagMapping,Information
              ].freeze
end

#table_exists?(table_name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/schema.rb', line 22

def table_exists?(table_name)
  @db.table_exists? table_name
end