Module: Dcmgr::Models::InheritableSchema::ClassMethods
- Defined in:
- lib/dcmgr/models/base_new.rb
Instance Method Summary collapse
-
#create_table ⇒ Object
Creates table, using the column information from set_schema.
-
#create_table! ⇒ Object
Drops the table if it exists and then runs create_table.
-
#create_table? ⇒ Boolean
Creates the table unless the table already exists.
-
#drop_table ⇒ Object
Drops table.
- #inheritable_schema(name = nil, &blk) ⇒ Object
- #schema ⇒ Object
- #schema_builders ⇒ Object
-
#table_exists? ⇒ Boolean
Returns true if table exists, false otherwise.
Instance Method Details
#create_table ⇒ Object
Creates table, using the column information from set_schema.
198 199 200 201 202 |
# File 'lib/dcmgr/models/base_new.rb', line 198 def create_table db.create_table(table_name, :generator=>schema) @db_schema = get_db_schema(true) columns end |
#create_table! ⇒ Object
Drops the table if it exists and then runs create_table. Should probably not be used except in testing.
207 208 209 210 |
# File 'lib/dcmgr/models/base_new.rb', line 207 def create_table! drop_table rescue nil create_table end |
#create_table? ⇒ Boolean
Creates the table unless the table already exists
213 214 215 |
# File 'lib/dcmgr/models/base_new.rb', line 213 def create_table? create_table unless table_exists? end |
#drop_table ⇒ Object
Drops table.
218 219 220 |
# File 'lib/dcmgr/models/base_new.rb', line 218 def drop_table db.drop_table(table_name) end |
#inheritable_schema(name = nil, &blk) ⇒ Object
252 253 254 255 |
# File 'lib/dcmgr/models/base_new.rb', line 252 def inheritable_schema(name=nil, &blk) set_dataset(db[name || implicit_table_name]) self.schema_builders << blk end |
#schema ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/dcmgr/models/base_new.rb', line 227 def schema builders = [] c = self begin builders << c.schema_builders if c.respond_to?(:schema_builders) end while((c = c.superclass) && c != Sequel::Model) builders = builders.reverse.flatten builders.delete(nil) schema = Sequel::Schema::Generator.new(db) { primary_key :id, Integer, :null=>false, :unsigned=>true } builders.each { |blk| schema.instance_eval(&blk) } set_primary_key(schema.primary_key_name) if schema.primary_key_name schema end |
#schema_builders ⇒ Object
248 249 250 |
# File 'lib/dcmgr/models/base_new.rb', line 248 def schema_builders @schema_builders ||= [] end |
#table_exists? ⇒ Boolean
Returns true if table exists, false otherwise.
223 224 225 |
# File 'lib/dcmgr/models/base_new.rb', line 223 def table_exists? db.table_exists?(table_name) end |