Class: UnitRecord::ColumnCacher
- Inherits:
-
Object
- Object
- UnitRecord::ColumnCacher
- Includes:
- ActiveRecord::ConnectionAdapters::SchemaStatements
- Defined in:
- lib/unit_record/column_cacher.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_index(table_name, column_name, options = {}) ⇒ Object
- #create_table(table_name, options = {}) {|table_definition| ... } ⇒ Object
- #native_database_types ⇒ Object
Class Method Details
.cache(schema_file) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/unit_record/column_cacher.rb', line 5 def self.cache(schema_file) (class << ActiveRecord::Schema; self; end).class_eval do def define(={}, &block) UnitRecord::ColumnCacher.new.instance_eval(&block) end end load schema_file end |
Instance Method Details
#add_index(table_name, column_name, options = {}) ⇒ Object
14 15 |
# File 'lib/unit_record/column_cacher.rb', line 14 def add_index(table_name, column_name, = {}) end |
#create_table(table_name, options = {}) {|table_definition| ... } ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/unit_record/column_cacher.rb', line 17 def create_table(table_name, ={}) table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new(self) table_definition.primary_key([:primary_key] || "id") unless [:id] == false yield table_definition ActiveRecord::Base.cached_columns[table_name.to_s] = table_definition.columns.map do |c| ActiveRecord::ConnectionAdapters::Column.new(c.name.to_s, c.default, c.sql_type, c.null) end end |
#native_database_types ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/unit_record/column_cacher.rb', line 27 def native_database_types # Copied from the MysqlAdapter so ColumnDefinition#sql_type will work { :primary_key => "int(11) DEFAULT NULL auto_increment PRIMARY KEY", :string => { :name => "varchar", :limit => 255 }, :text => { :name => "text" }, :integer => { :name => "int", :limit => 11 }, :float => { :name => "float" }, :decimal => { :name => "decimal" }, :datetime => { :name => "datetime" }, :timestamp => { :name => "datetime" }, :time => { :name => "time" }, :date => { :name => "date" }, :binary => { :name => "blob" }, :boolean => { :name => "tinyint", :limit => 1 } } end |