Class: ActiveRecord::BaseWithoutTable

Inherits:
Base
  • Object
show all
Defined in:
lib/active_record/base_without_table.rb

Overview

Get the power of ActiveRecord models, including validation, without having a table in the database.

Usage

class Contact < ActiveRecord::BaseWithoutTable
  column :name, :string
  column :email_address, :string
  column :message, :text
end

validates_presence_of :name, :email_address, :string

This model can be used just like a regular model based on a table, except it will never be saved to the database.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.column(name, sql_type = nil, default = nil, null = true) ⇒ Object

:nodoc:



30
31
32
33
# File 'lib/active_record/base_without_table.rb', line 30

def column(name, sql_type = nil, default = nil, null = true) # :nodoc:
  columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
  reset_column_information
end

.reset_column_informationObject

Do not reset @columns



36
37
38
39
# File 'lib/active_record/base_without_table.rb', line 36

def reset_column_information # :nodoc:
  generated_methods.each { |name| undef_method(name) }
  @column_names = @columns_hash = @content_columns = @dynamic_methods_hash = @generated_methods = nil
end

Instance Method Details

#create_or_updateObject

:nodoc:



22
23
24
# File 'lib/active_record/base_without_table.rb', line 22

def create_or_update # :nodoc:
  errors.empty?
end