Class: Ext::ActiveRecord::Models::AllYourBase

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

Class Method Summary collapse

Class Method Details

.check_createObject

This method checks if your table exists, otherwise it calls the #schema with the model’s connection.



70
71
72
73
74
75
# File 'lib/ext/active_record.rb', line 70

def check_create
  if schema and connection and not table_exists?
    schema.call(connection)
    reset_column_information
  end
end

.reset_table_nameObject

I has to override this method too to get the right table name working



89
90
91
92
93
94
95
# File 'lib/ext/active_record.rb', line 89

def reset_table_name #:nodoc:
  table_name = Inflector.underscore(Inflector.demodulize(self.name))
  table_name = Inflector.pluralize(table_name) if pluralize_table_names
  name = "#{table_name_prefix}#{table_name}#{table_name_suffix}"
  set_table_name(name)
  name
end

.schema(&block) ⇒ Object

This is a facility to create your schemas.

Example (in your models)

class Post < Base
  self.schema do |c|
    c.create_table table_name, :force=>true do |t|
      t.column :title, :string, :limit => 255
      t.column :body, :text
    end
  end
end


63
64
65
66
# File 'lib/ext/active_record.rb', line 63

def schema(&block)
  @schema = block if block_given?
  @schema
end

.table_name_prefixObject

The default prefix for Camping model classes is the topmost module name lowercase and followed with an underscore.

Tepee::Models::Page.table_name_prefix
  #=> "tepee_pages"


83
84
85
# File 'lib/ext/active_record.rb', line 83

def table_name_prefix
  "#{name[/\w+/]}_".downcase.sub(/^(activerecord|camping)_/i,'')
end