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.
225 226 227 228 229 |
# File 'lib/dcmgr/models/base_new.rb', line 225 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.
234 235 236 237 |
# File 'lib/dcmgr/models/base_new.rb', line 234 def create_table! drop_table rescue nil create_table end |
#create_table? ⇒ Boolean
Creates the table unless the table already exists
240 241 242 |
# File 'lib/dcmgr/models/base_new.rb', line 240 def create_table? create_table unless table_exists? end |
#drop_table ⇒ Object
Drops table.
245 246 247 |
# File 'lib/dcmgr/models/base_new.rb', line 245 def drop_table db.drop_table(table_name) end |
#inheritable_schema(name = nil, &blk) ⇒ Object
279 280 281 282 |
# File 'lib/dcmgr/models/base_new.rb', line 279 def inheritable_schema(name=nil, &blk) set_dataset(db[name || implicit_table_name]) self.schema_builders << blk end |
#schema ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/dcmgr/models/base_new.rb', line 254 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
275 276 277 |
# File 'lib/dcmgr/models/base_new.rb', line 275 def schema_builders @schema_builders ||= [] end |
#table_exists? ⇒ Boolean
Returns true if table exists, false otherwise.
250 251 252 |
# File 'lib/dcmgr/models/base_new.rb', line 250 def table_exists? db.table_exists?(table_name) end |