From 900470cf3cd346ad1b17cf6902f3f98e6dae7709 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 20:13:24 -0300 Subject: Added docs for #indexes on adapters --- activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 1 + .../lib/active_record/connection_adapters/postgresql_adapter.rb | 2 +- activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 1270a1292c..46842df024 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -611,6 +611,7 @@ module ActiveRecord super(table_name, options) end + # Returns an array of indexes for the given table. def indexes(table_name, name = nil)#:nodoc: indexes = [] current_index = nil diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 3f70d5d0f7..8d336de498 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -690,7 +690,7 @@ module ActiveRecord [schema, table] end - # Returns the list of all indexes for a table. + # Returns an array of indexes for the given table. def indexes(table_name, name = nil) schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',') result = query(<<-SQL, name) diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index a9dc756bbb..3eaa0f642f 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -263,6 +263,7 @@ module ActiveRecord end end + # Returns an array of indexes for the given table. def indexes(table_name, name = nil) #:nodoc: exec_query("PRAGMA index_list(#{quote_table_name(table_name)})", name).map do |row| IndexDefinition.new( -- cgit v1.2.3 From 5d59cd8d6a8181cafa55af6189e0984b618e19be Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 20:20:25 -0300 Subject: Added docs for #columns on some adapters --- activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 1 + activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index c5a9ac683c..381995b1b6 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -626,6 +626,7 @@ module ActiveRecord indexes end + # Returns an array of +MysqlColumn+ objects for the table specified by +table_name+. def columns(table_name, name = nil)#:nodoc: sql = "SHOW FIELDS FROM #{quote_table_name(table_name)}" columns = [] diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 24d1bed165..90f20c15b5 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -244,6 +244,7 @@ module ActiveRecord end end + # Returns an array of +SQLiteColumn+ objects for the table specified by +table_name+. def columns(table_name, name = nil) #:nodoc: table_structure(table_name).map do |field| case field["dflt_value"] -- cgit v1.2.3 From e382d95e1e491c48f583d2bf13a9f50d7b3ee6ef Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 20:26:20 -0300 Subject: Added docs for #rename_table on some adapters --- activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 4 ++++ .../lib/active_record/connection_adapters/postgresql_adapter.rb | 3 +++ activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 4 ++++ 3 files changed, 11 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 381995b1b6..6342504f83 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -640,6 +640,10 @@ module ActiveRecord super(table_name, options.reverse_merge(:options => "ENGINE=InnoDB")) end + # Renames a table. + # + # Example: + # rename_table('octopuses', 'octopi') def rename_table(table_name, new_name) execute "RENAME TABLE #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}" end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index d6beb67c4d..9f9b40e108 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -855,6 +855,9 @@ module ActiveRecord end # Renames a table. + # + # Example: + # rename_table('octopuses', 'octopi') def rename_table(name, new_name) execute "ALTER TABLE #{quote_table_name(name)} RENAME TO #{quote_table_name(new_name)}" end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 90f20c15b5..afb768c6a0 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -284,6 +284,10 @@ module ActiveRecord exec_query "DROP INDEX #{quote_column_name(index_name)}" end + # Renames a table. + # + # Example: + # rename_table('octopuses', 'octopi') def rename_table(name, new_name) exec_query "ALTER TABLE #{quote_table_name(name)} RENAME TO #{quote_table_name(new_name)}" end -- cgit v1.2.3 From 616eef33a5ffe006609e75b67cadcc4c89ff09b4 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 20:39:00 -0300 Subject: Added doc for #table_exists? --- .../active_record/connection_adapters/abstract/schema_statements.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 8bae50885f..9a6f36598b 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -17,6 +17,10 @@ module ActiveRecord # def tables(name = nil) end + # Checks to see if the table +table_name+ exists on the database. + # + # === Example + # table_exists?(:developers) def table_exists?(table_name) tables.include?(table_name.to_s) end -- cgit v1.2.3 From 0ce94f40203d4dcff577d8e3aadbc963adca569c Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 20:39:26 -0300 Subject: dot missing here --- .../lib/active_record/connection_adapters/abstract/schema_statements.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 9a6f36598b..9f9c2c42cb 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -28,7 +28,7 @@ module ActiveRecord # Returns an array of indexes for the given table. # def indexes(table_name, name = nil) end - # Checks to see if an index exists on a table for a given index definition + # Checks to see if an index exists on a table for a given index definition. # # === Examples # # Check an index exists -- cgit v1.2.3 From 868fb3825cb9631bdf284668f354f7bb1ea0d61b Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 20:50:15 -0300 Subject: Make this docs more consistent with the rest of the docs present --- activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 5 +++-- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 3 ++- activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 6342504f83..82cfd10480 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -208,13 +208,13 @@ module ActiveRecord true end - # Returns +true+, since this connection adapter supports prepared statement + # Returns true, since this connection adapter supports prepared statement # caching. def supports_statement_cache? true end - # Returns true. + # Returns true, since this connection adapter supports migrations. def supports_migrations? #:nodoc: true end @@ -224,6 +224,7 @@ module ActiveRecord true end + # Returns true, since this connection adapter supports savepoints. def supports_savepoints? #:nodoc: true end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 9f9b40e108..b1d7fa1bd6 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -290,7 +290,7 @@ module ActiveRecord NATIVE_DATABASE_TYPES end - # Does PostgreSQL support migrations? + # Returns true, since this connection adapter supports migrations. def supports_migrations? true end @@ -316,6 +316,7 @@ module ActiveRecord true end + # Returns true, since this connection adapter supports savepoints. def supports_savepoints? true end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index afb768c6a0..432bbbba45 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -72,7 +72,7 @@ module ActiveRecord true end - # Returns true. + # Returns true, since this connection adapter supports migrations. def supports_migrations? #:nodoc: true end -- cgit v1.2.3 From 3e678daa720f26cffc889a301a1d27b89294d14a Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 20:58:02 -0300 Subject: Added some docs on SQLite adapter --- activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 432bbbba45..4540cf015b 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -58,10 +58,12 @@ module ActiveRecord 'SQLite' end + # Returns true if SQLite version is '2.0.0' or greater, false otherwise. def supports_ddl_transactions? sqlite_version >= '2.0.0' end + # Returns true if SQLite version is '3.6.8' or greater, false otherwise. def supports_savepoints? sqlite_version >= '3.6.8' end @@ -86,6 +88,7 @@ module ActiveRecord true end + # Returns true if SQLite version is '3.1.6' or greater, false otherwise. def supports_add_column? sqlite_version >= '3.1.6' end @@ -103,10 +106,12 @@ module ActiveRecord @statements.clear end + # Returns true if SQLite version is '3.2.6' or greater, false otherwise. def supports_count_distinct? #:nodoc: sqlite_version >= '3.2.6' end + # Returns true if SQLite version is '3.1.0' or greater, false otherwise. def supports_autoincrement? #:nodoc: sqlite_version >= '3.1.0' end -- cgit v1.2.3 From 17d34d149e0622a2c4cdaecd7f3356f33a4a8b12 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 21:01:29 -0300 Subject: Added docs for #version on mysql_adapter --- activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 82cfd10480..eaadbc179b 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -882,6 +882,7 @@ module ActiveRecord version[0] >= 5 end + # Returns the version of the connected MySQL server. def version @version ||= @connection.server_info.scan(/^(\d+)\.(\d+)\.(\d+)/).flatten.map { |v| v.to_i } end -- cgit v1.2.3 From 4d0464187cebdf513f91a61c356a2452043d27e7 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 21:02:49 -0300 Subject: Fix #postgresql_version docs --- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index b1d7fa1bd6..aa9c9f5889 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -943,7 +943,7 @@ module ActiveRecord end protected - # Returns the version of the connected PostgreSQL version. + # Returns the version of the connected PostgreSQL server. def postgresql_version @postgresql_version ||= if @connection.respond_to?(:server_version) -- cgit v1.2.3 From a510f5c39fc8365ef2dffb8f0cd81c755f0b902e Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 21:13:35 -0300 Subject: Better docs formatting --- .../connection_adapters/abstract/database_limits.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb index 29ac9341ec..30ccb8f0a4 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb @@ -2,52 +2,53 @@ module ActiveRecord module ConnectionAdapters # :nodoc: module DatabaseLimits - # the maximum length of a table alias + # Returns the maximum length of a table alias. def table_alias_length 255 end - # the maximum length of a column name + # Returns the maximum length of a column name. def column_name_length 64 end - # the maximum length of a table name + # Returns the maximum length of a table name. def table_name_length 64 end - # the maximum length of an index name + # Returns the maximum length of an index name. def index_name_length 64 end - # the maximum number of columns per table + # Returns the maximum number of columns per table. def columns_per_table 1024 end - # the maximum number of indexes per table + # Returns the maximum number of indexes per table. def indexes_per_table 16 end - # the maximum number of columns in a multicolumn index + # Returns the maximum number of columns in a multicolumn index. def columns_per_multicolumn_index 16 end - # the maximum number of elements in an IN (x,y,z) clause. nil means no limit + # Returns the maximum number of elements in an IN (x,y,z) clause. + # nil means no limit. def in_clause_length nil end - # the maximum length of an SQL query + # Returns the maximum length of an SQL query. def sql_query_length 1048575 end - # maximum number of joins in a single query + # Returns maximum number of joins in a single query. def joins_per_query 256 end -- cgit v1.2.3 From 8f1b141b3f766a3a724648b2a9437ee5f18aaad9 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 21:17:51 -0300 Subject: Fixed punctuation errors. --- .../active_record/connection_adapters/abstract/connection_pool.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index b4db1eed18..6f21cea288 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -113,7 +113,7 @@ module ActiveRecord end end - # A cached lookup for table existence + # A cached lookup for table existence. def table_exists?(name) return true if @tables.key? name @@ -135,7 +135,7 @@ module ActiveRecord @tables.clear end - # Clear out internal caches for table with +table_name+ + # Clear out internal caches for table with +table_name+. def clear_table_cache!(table_name) @columns.delete table_name @columns_hash.delete table_name @@ -193,7 +193,7 @@ module ActiveRecord @connections = [] end - # Clears the cache which maps classes + # Clears the cache which maps classes. def clear_reloadable_connections! @reserved_connections.each do |name, conn| checkin conn @@ -365,7 +365,7 @@ module ActiveRecord @connection_pools.each_value {|pool| pool.release_connection } end - # Clears the cache which maps classes + # Clears the cache which maps classes. def clear_reloadable_connections! @connection_pools.each_value {|pool| pool.clear_reloadable_connections! } end -- cgit v1.2.3 From 0887385d8e18acda857fccc7f5c97acfec129902 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Apr 2011 21:30:30 -0300 Subject: Added missing docs to mysql2_adapter --- .../lib/active_record/connection_adapters/mysql2_adapter.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 7ac72acd58..fc91814275 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -131,6 +131,7 @@ module ActiveRecord ADAPTER_NAME end + # Returns true, since this connection adapter supports migrations. def supports_migrations? true end @@ -139,6 +140,7 @@ module ActiveRecord true end + # Returns true, since this connection adapter supports savepoints. def supports_savepoints? true end @@ -376,6 +378,10 @@ module ActiveRecord end end + # Drops a MySQL database. + # + # Example: + # drop_database('sebastian_development') def drop_database(name) #:nodoc: execute "DROP DATABASE IF EXISTS `#{name}`" end @@ -406,6 +412,7 @@ module ActiveRecord super(table_name, options) end + # Returns an array of indexes for the given table. def indexes(table_name, name = nil) indexes = [] current_index = nil @@ -423,6 +430,7 @@ module ActiveRecord indexes end + # Returns an array of +Mysql2Column+ objects for the table specified by +table_name+. def columns(table_name, name = nil) sql = "SHOW FIELDS FROM #{quote_table_name(table_name)}" columns = [] @@ -437,6 +445,10 @@ module ActiveRecord super(table_name, options.reverse_merge(:options => "ENGINE=InnoDB")) end + # Renames a table. + # + # Example: + # rename_table('octopuses', 'octopi') def rename_table(table_name, new_name) execute "RENAME TABLE #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}" end @@ -521,6 +533,7 @@ module ActiveRecord variables.first['Value'] unless variables.empty? end + # Returns a table's primary key and belonging sequence. def pk_and_sequence_for(table) keys = [] result = execute("describe #{quote_table_name(table)}") -- cgit v1.2.3 From c60e207674fb7844c9586f98be6ad930362b1a3d Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 24 Apr 2011 19:44:12 -0300 Subject: Better formatting here --- activerecord/lib/active_record/validations.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index d73fce9fd0..de36dd20b3 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -30,7 +30,7 @@ module ActiveRecord include ActiveModel::Validations module ClassMethods - # Creates an object just like Base.create but calls save! instead of save + # Creates an object just like Base.create but calls save! instead of +save+ # so an exception is raised if the record is invalid. def create!(attributes = nil, &block) if attributes.is_a?(Array) @@ -44,13 +44,13 @@ module ActiveRecord end end - # The validation process on save can be skipped by passing :validate => false. The regular Base#save method is + # The validation process on save can be skipped by passing :validate => false. The regular Base#save method is # replaced with this when the validations module is mixed in, which it is by default. def save(options={}) perform_validations(options) ? super : false end - # Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false + # Attempts to save the record just like Base#save but will raise a +RecordInvalid+ exception instead of returning false # if the record is not valid. def save!(options={}) perform_validations(options) ? super : raise(RecordInvalid.new(self)) -- cgit v1.2.3