Wednesday, April 9, 2008

ActiveRecord Code Hacking

 

Class ActiveRecord::Schema < Migration

In: lib/active_record/schema.rb

Allows programmers to programmatically define a schema in a portable DSL. This means you can define tables, indexes, etc. without using SQL directly, so your applications can more easily support multiple databases.

 

Class ActiveRecord::Observer < Object

In: lib/active_record/observer.rb

Observer classes respond to lifecycle callbacks to implement trigger-like behavior outside the original class. This is a great way to reduce the clutter that normally comes when the model class is burdened with functionality that doesn’t pertain to the core responsibility of the class. Example:

  class CommentObserver < ActiveRecord::Observer
def after_save(comment)
Notifications.deliver_comment("admin@do.com", "New comment was posted", comment)
end
end


 




Class ActiveRecord::ConnectionAdapters::AbstractAdapter < Object



In: lib/active_record/connection_adapters/abstract_adapter.rb



All the concrete database adapters follow the interface laid down in this class. You can use this interface directly by borrowing the database connection from the Base with Base.connection.



Included Modules




These 3 modules should be overridden by sub-class of AbstractAdapter.



Included Classes


Class ActiveRecord::ConnectionAdapters::Column < Object



In: lib/active_record/connection_adapters/abstract/schema_definitions.rb



An abstract definition of a column in a table.



Methods



  • binary_to_string


  • human_name


  • klass


  • new


  • number?


  • string_to_binary


  • string_to_date


  • string_to_dummy_time


  • string_to_time


  • value_to_boolean


  • text?


  • type_cast(value) : Casts value (which is a String) to an appropriate instance.


  • type_cast_code : Generates the ruby code for evaluating the column's value.


  • simplified_type(field_type) : treat similar rails' data types(:date, :datetime, :text, etc.) as the same.
  • No comments:

     
    free hit counter
    hit counter