# # See http://railscasts.com/episodes/193-tableless-model # class Tableless31Model < ActiveRecord::Base def self.columns @columns ||= []; end 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_hash @columns_hash ||= Hash[columns.map { |column| [column.name, column] }] end def self.column_names @column_names ||= columns.map { |column| column.name } end def self.column_defaults @column_defaults ||= columns.map { |column| [column.name, nil] }.inject({}) { |m, e| m[e[0]] = e[1]; m } end # Override the save method to prevent exceptions. def save(validate = true) validate ? valid? : true end def initialize(attributes = nil) super(attributes) end end