Sha256: 10878278ede41103a24e3e0efaf31122854cdddea7b5b9e637c19e4fcc92babd

Contents?: true

Size: 913 Bytes

Versions: 2

Compression:

Stored size: 913 Bytes

Contents

#
# 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
auxiliary_addons-0.5.6 lib/auxiliary_addons/tableless31_model.rb
auxiliary_addons-0.5.5 lib/auxiliary_addons/tableless31_model.rb