Class: Lipsiadmin::DataBase::WithoutTable
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Lipsiadmin::DataBase::WithoutTable
- Defined in:
- lib/data_base/without_table.rb
Overview
This class create a fake table that can be usefull if you need for example perform validations. Take a look to this test case:
Examples:
class Contact < Lipsiadmin::DataBase::WithoutTable
column :name, :string
column :company, :string
column :telephone, :string
column :email, :string
column :message, :text
validates_presence_of :name, :message
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
end
Now we need to validate a contact, and if the validations is okey send an email or if not raise errors
@contact = Contact.new(params[:contact])
if @contact.valid?
Notifier.deliver_support_request(@contact)
else
flash[:notice] = "There are some problems"
render :action => :support_request
end
Class Method Summary collapse
-
.column(name, sql_type = nil, default = nil, null = true) ⇒ Object
Define columns for a this fake table.
-
.columns ⇒ Object
Returns columns for this fake table.
-
.reset_column_information ⇒ Object
Resets all the cached information about columns, which will cause them to be reloaded on the next request.
Instance Method Summary collapse
-
#create_or_update ⇒ Object
:nodoc:.
Class Method Details
.column(name, sql_type = nil, default = nil, null = true) ⇒ Object
Define columns for a this fake table
43 44 45 46 |
# File 'lib/data_base/without_table.rb', line 43 def column(name, sql_type = nil, default = nil, null = true) columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) reset_column_information end |
.columns ⇒ Object
Returns columns for this fake table
38 39 40 |
# File 'lib/data_base/without_table.rb', line 38 def columns() @columns ||= [] end |
.reset_column_information ⇒ Object
Resets all the cached information about columns, which will cause them to be reloaded on the next request.
49 50 51 52 |
# File 'lib/data_base/without_table.rb', line 49 def reset_column_information 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_update ⇒ Object
:nodoc:
32 33 34 |
# File 'lib/data_base/without_table.rb', line 32 def create_or_update#:nodoc: errors.empty? end |