Skip to content

Instantly share code, notes, and snippets.

@0x00b1
Forked from matpowel/tableless.rb
Created March 14, 2014 19:33
Show Gist options
  • Save 0x00b1/9555068 to your computer and use it in GitHub Desktop.
Save 0x00b1/9555068 to your computer and use it in GitHub Desktop.
class Tableless < ActiveRecord::Base
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new( name.to_s, default, sql_type.to_s, null )
end
def self.columns()
@columns ||= [];
end
def self.columns_hash
h = {}
for c in self.columns
h[c.name] = c
end
return h
end
def self.column_defaults
Hash[self.columns.map{ |col|
[col.name, col.default]
}]
end
def self.descends_from_active_record?
return true
end
def persisted?
return false
end
# override the save method to prevent exceptions
def save( validate = true )
validate ? valid? : true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment