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.
227 228 229 230 231 |
# File 'lib/dcmgr/models/base_new.rb', line 227 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.
236 237 238 239 |
# File 'lib/dcmgr/models/base_new.rb', line 236 def create_table! drop_table rescue nil create_table end |
#create_table? ⇒ Boolean
Creates the table unless the table already exists
242 243 244 |
# File 'lib/dcmgr/models/base_new.rb', line 242 def create_table? create_table unless table_exists? end |
#drop_table ⇒ Object
Drops table.
247 248 249 |
# File 'lib/dcmgr/models/base_new.rb', line 247 def drop_table db.drop_table(table_name) end |
#inheritable_schema(name = nil, &blk) ⇒ Object
281 282 283 284 |
# File 'lib/dcmgr/models/base_new.rb', line 281 def inheritable_schema(name=nil, &blk) set_dataset(db[name || implicit_table_name]) self.schema_builders << blk end |
#schema ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/dcmgr/models/base_new.rb', line 256 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
277 278 279 |
# File 'lib/dcmgr/models/base_new.rb', line 277 def schema_builders @schema_builders ||= [] end |
#table_exists? ⇒ Boolean
Returns true if table exists, false otherwise.
252 253 254 |
# File 'lib/dcmgr/models/base_new.rb', line 252 def table_exists? db.table_exists?(table_name) end |