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.
233 234 235 236 237 |
# File 'lib/dcmgr/models/base_new.rb', line 233 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.
242 243 244 245 |
# File 'lib/dcmgr/models/base_new.rb', line 242 def create_table! drop_table rescue nil create_table end |
#create_table? ⇒ Boolean
Creates the table unless the table already exists
248 249 250 |
# File 'lib/dcmgr/models/base_new.rb', line 248 def create_table? create_table unless table_exists? end |
#drop_table ⇒ Object
Drops table.
253 254 255 |
# File 'lib/dcmgr/models/base_new.rb', line 253 def drop_table db.drop_table(table_name) end |
#inheritable_schema(name = nil, &blk) ⇒ Object
287 288 289 290 |
# File 'lib/dcmgr/models/base_new.rb', line 287 def inheritable_schema(name=nil, &blk) set_dataset(db[name || implicit_table_name]) self.schema_builders << blk end |
#schema ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/dcmgr/models/base_new.rb', line 262 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
283 284 285 |
# File 'lib/dcmgr/models/base_new.rb', line 283 def schema_builders @schema_builders ||= [] end |
#table_exists? ⇒ Boolean
Returns true if table exists, false otherwise.
258 259 260 |
# File 'lib/dcmgr/models/base_new.rb', line 258 def table_exists? db.table_exists?(table_name) end |