Sha256: 427fa71a5766605a7eb785a09fd52ccdba566d25712ba86fed8244224178a60b

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 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

1 entries across 1 versions & 1 rubygems

Version Path
auxiliary_addons-0.5.7 lib/auxiliary_addons/tableless31_model.rb