Module: Schema
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #config(env, file) ⇒ Object
- #connect(str) ⇒ Object
- #create! ⇒ Object
- #current_connect ⇒ Object
- #drop! ⇒ Object
- #models ⇒ Object
- #table_exists?(table_name) ⇒ Boolean
Instance Attribute Details
#db ⇒ Object (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_connect ⇒ Object
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 |
#models ⇒ Object
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
22 23 24 |
# File 'app/models/schema.rb', line 22 def table_exists?(table_name) @db.table_exists? table_name end |