diff options
author | Akira Matsuda <ronnie@dio.jp> | 2016-12-23 15:51:11 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2016-12-24 23:39:36 +0900 |
commit | 5b14129d8d4ad302b4e11df6bd5c7891b75f393c (patch) | |
tree | cfcd0a51846f540f40cc314e29a7070b415a9219 /activerecord/lib/active_record/connection_adapters | |
parent | 6c5bbb4b7d3bdd1b43e512fb6ae764c373c7827b (diff) | |
download | rails-5b14129d8d4ad302b4e11df6bd5c7891b75f393c.tar.gz rails-5b14129d8d4ad302b4e11df6bd5c7891b75f393c.tar.bz2 rails-5b14129d8d4ad302b4e11df6bd5c7891b75f393c.zip |
Privatize unneededly protected methods in Active Record
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
8 files changed, 58 insertions, 66 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 947796eea0..fab5bd0db7 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -360,34 +360,34 @@ module ActiveRecord end alias join_to_delete join_to_update - protected + private # Returns a subquery for the given key using the join information. - def subquery_for(key, select) + def subquery_for(key, select) # :doc: subselect = select.clone subselect.projections = [key] subselect end # Returns an ActiveRecord::Result instance. - def select(sql, name = nil, binds = []) + def select(sql, name = nil, binds = []) # :doc: exec_query(sql, name, binds, prepare: false) end - def select_prepared(sql, name = nil, binds = []) + def select_prepared(sql, name = nil, binds = []) # :doc: exec_query(sql, name, binds, prepare: true) end - def sql_for_insert(sql, pk, id_value, sequence_name, binds) + def sql_for_insert(sql, pk, id_value, sequence_name, binds) # :doc: [sql, binds] end - def last_inserted_id(result) + def last_inserted_id(result) # :doc: row = result.rows.first row && row.first end - def binds_from_relation(relation, binds) + def binds_from_relation(relation, binds) # :doc: if relation.is_a?(Relation) && binds.empty? relation, binds = relation.arel, relation.bound_attributes end 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 f8bda848f7..2b131045db 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -1169,9 +1169,9 @@ module ActiveRecord raise NotImplementedError, "#{self.class} does not support changing column comments" end - protected + private - def add_index_sort_order(quoted_columns, **options) + def add_index_sort_order(quoted_columns, **options) # :doc: if order = options[:order] case order when Hash @@ -1186,7 +1186,7 @@ module ActiveRecord end # Overridden by the MySQL adapter for supporting index lengths - def add_options_for_index_columns(quoted_columns, **options) + def add_options_for_index_columns(quoted_columns, **options) # :doc: if supports_index_sort_order? quoted_columns = add_index_sort_order(quoted_columns, options) end @@ -1194,14 +1194,14 @@ module ActiveRecord quoted_columns end - def quoted_columns_for_index(column_names, **options) + def quoted_columns_for_index(column_names, **options) # :doc: return [column_names] if column_names.is_a?(String) quoted_columns = Hash[column_names.map { |name| [name.to_sym, quote_column_name(name).dup] }] add_options_for_index_columns(quoted_columns, options).values end - def index_name_for_remove(table_name, options = {}) + def index_name_for_remove(table_name, options = {}) # :doc: return options[:name] if can_remove_index_by_name?(options) checks = [] @@ -1231,7 +1231,7 @@ module ActiveRecord end end - def rename_table_indexes(table_name, new_name) + def rename_table_indexes(table_name, new_name) # :doc: indexes(new_name).each do |index| generated_index_name = index_name(table_name, column: index.columns) if generated_index_name == index.name @@ -1240,7 +1240,7 @@ module ActiveRecord end end - def rename_column_indexes(table_name, column_name, new_column_name) + def rename_column_indexes(table_name, column_name, new_column_name) # :doc: column_name, new_column_name = column_name.to_s, new_column_name.to_s indexes(table_name).each do |index| next unless index.columns.include?(new_column_name) @@ -1253,7 +1253,6 @@ module ActiveRecord end end - private def create_table_definition(*args) TableDefinition.new(*args) end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 284529b46e..1badbb576d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -499,9 +499,9 @@ module ActiveRecord result end - protected + private - def initialize_type_map(m) # :nodoc: + def initialize_type_map(m) register_class_with_limit m, %r(boolean)i, Type::Boolean register_class_with_limit m, %r(char)i, Type::String register_class_with_limit m, %r(binary)i, Type::Binary @@ -532,37 +532,37 @@ module ActiveRecord end end - def reload_type_map # :nodoc: + def reload_type_map type_map.clear initialize_type_map(type_map) end - def register_class_with_limit(mapping, key, klass) # :nodoc: + def register_class_with_limit(mapping, key, klass) mapping.register_type(key) do |*args| limit = extract_limit(args.last) klass.new(limit: limit) end end - def register_class_with_precision(mapping, key, klass) # :nodoc: + def register_class_with_precision(mapping, key, klass) mapping.register_type(key) do |*args| precision = extract_precision(args.last) klass.new(precision: precision) end end - def extract_scale(sql_type) # :nodoc: + def extract_scale(sql_type) case sql_type when /\((\d+)\)/ then 0 when /\((\d+)(,(\d+))\)/ then $3.to_i end end - def extract_precision(sql_type) # :nodoc: + def extract_precision(sql_type) $1.to_i if sql_type =~ /\((\d+)(,\d+)?\)/ end - def extract_limit(sql_type) # :nodoc: + def extract_limit(sql_type) case sql_type when /^bigint/i 8 @@ -571,7 +571,7 @@ module ActiveRecord end end - def translate_exception_class(e, sql) + def translate_exception_class(e, sql) # :doc: begin message = "#{e.class.name}: #{e.message}: #{sql}" rescue Encoding::CompatibilityError @@ -583,7 +583,7 @@ module ActiveRecord exception end - def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) + def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) # :doc: @instrumenter.instrument( "sql.active_record", sql: sql, @@ -596,7 +596,7 @@ module ActiveRecord raise translate_exception_class(e, sql) end - def translate_exception(exception, message) + def translate_exception(exception, message) # :doc: # override in derived class case exception when RuntimeError @@ -606,11 +606,11 @@ module ActiveRecord end end - def without_prepared_statement?(binds) + def without_prepared_statement?(binds) # :doc: !prepared_statements || binds.empty? end - def column_for(table_name, column_name) # :nodoc: + def column_for(table_name, column_name) column_name = column_name.to_s columns(table_name).detect { |c| c.name == column_name } || raise(ActiveRecordError, "No such column: #{table_name}.#{column_name}") diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 6985d2c1b2..68a88e71ba 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -649,9 +649,9 @@ module ActiveRecord !native_database_types[type].nil? end - protected + private - def initialize_type_map(m) # :nodoc: + def initialize_type_map(m) super register_class_with_limit m, %r(char)i, MysqlString @@ -691,7 +691,7 @@ module ActiveRecord end end - def register_integer_type(mapping, key, options) # :nodoc: + def register_integer_type(mapping, key, options) mapping.register_type(key) do |sql_type| if /\bunsigned\b/.match?(sql_type) Type::UnsignedInteger.new(options) @@ -701,7 +701,7 @@ module ActiveRecord end end - def extract_precision(sql_type) + def extract_precision(sql_type) # :doc: if /time/.match?(sql_type) super || 0 else @@ -709,11 +709,11 @@ module ActiveRecord end end - def fetch_type_metadata(sql_type, extra = "") + def fetch_type_metadata(sql_type, extra = "") # :doc: MySQL::TypeMetadata.new(super(sql_type), extra: extra) end - def add_index_length(quoted_columns, **options) + def add_index_length(quoted_columns, **options) # :doc: if length = options[:length] case length when Hash @@ -727,7 +727,7 @@ module ActiveRecord quoted_columns end - def add_options_for_index_columns(quoted_columns, **options) + def add_options_for_index_columns(quoted_columns, **options) # :doc: quoted_columns = add_index_length(quoted_columns, options) super end @@ -743,7 +743,7 @@ module ActiveRecord ER_CANNOT_ADD_FOREIGN = 1215 ER_CANNOT_CREATE_TABLE = 1005 - def translate_exception(exception, message) + def translate_exception(exception, message) # :doc: case error_number(exception) when ER_DUP_ENTRY RecordNotUnique.new(message) @@ -770,13 +770,13 @@ module ActiveRecord end end - def add_column_sql(table_name, column_name, type, options = {}) + def add_column_sql(table_name, column_name, type, options = {}) # :doc: td = create_table_definition(table_name) cd = td.new_column_definition(column_name, type, options) schema_creation.accept(AddColumnDefinition.new(cd)) end - def change_column_sql(table_name, column_name, type, options = {}) + def change_column_sql(table_name, column_name, type, options = {}) # :doc: column = column_for(table_name, column_name) unless options_include_default?(options) @@ -796,7 +796,7 @@ module ActiveRecord schema_creation.accept(ChangeColumnDefinition.new(cd, column.name)) end - def rename_column_sql(table_name, column_name, new_column_name) + def rename_column_sql(table_name, column_name, new_column_name) # :doc: column = column_for(table_name, column_name) options = { default: column.default, @@ -810,35 +810,33 @@ module ActiveRecord schema_creation.accept(ChangeColumnDefinition.new(cd, column.name)) end - def remove_column_sql(table_name, column_name, type = nil, options = {}) + def remove_column_sql(table_name, column_name, type = nil, options = {}) # :doc: "DROP #{quote_column_name(column_name)}" end - def remove_columns_sql(table_name, *column_names) + def remove_columns_sql(table_name, *column_names) # :doc: column_names.map { |column_name| remove_column_sql(table_name, column_name) } end - def add_index_sql(table_name, column_name, options = {}) + def add_index_sql(table_name, column_name, options = {}) # :doc: index_name, index_type, index_columns, _, index_algorithm, index_using = add_index_options(table_name, column_name, options) index_algorithm[0, 0] = ", " if index_algorithm.present? "ADD #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})#{index_algorithm}" end - def remove_index_sql(table_name, options = {}) + def remove_index_sql(table_name, options = {}) # :doc: index_name = index_name_for_remove(table_name, options) "DROP INDEX #{index_name}" end - def add_timestamps_sql(table_name, options = {}) + def add_timestamps_sql(table_name, options = {}) # :doc: [add_column_sql(table_name, :created_at, :datetime, options), add_column_sql(table_name, :updated_at, :datetime, options)] end - def remove_timestamps_sql(table_name, options = {}) + def remove_timestamps_sql(table_name, options = {}) # :doc: [remove_column_sql(table_name, :updated_at), remove_column_sql(table_name, :created_at)] end - private - # MySQL is too stupid to create a temporary table for use subquery, so we have # to give it some prompting in the form of a subsubquery. Ugh! def subquery_for(key, select) diff --git a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb index c7098105a8..1e13890eca 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb @@ -52,14 +52,12 @@ module ActiveRecord end alias :exec_update :exec_delete - protected + private - def last_inserted_id(result) + def last_inserted_id(result) # :doc: @connection.last_id end - private - def select_result(sql, name = nil, binds = []) if without_prepared_statement?(binds) execute_and_free(sql, name) { |result| yield result } diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb b/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb index 1412928ca5..56a445f086 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb @@ -34,7 +34,7 @@ module ActiveRecord parts.hash end - protected + private def unquote(part) if part && part.start_with?('"') part[1..-2] diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 6e43508714..72947a78f5 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -404,7 +404,7 @@ module ActiveRecord @connection.server_version end - protected + private # See http://www.postgresql.org/docs/current/static/errcodes-appendix.html VALUE_LIMIT_VIOLATION = "22001" @@ -415,7 +415,7 @@ module ActiveRecord SERIALIZATION_FAILURE = "40001" DEADLOCK_DETECTED = "40P01" - def translate_exception(exception, message) + def translate_exception(exception, message) # :doc: return exception unless exception.respond_to?(:result) case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE) @@ -438,8 +438,6 @@ module ActiveRecord end end - private - def get_oid_type(oid, fmod, column_name, sql_type = "") if !type_map.key?(oid) load_additional_types(type_map, [oid]) diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index a7c4a2cd86..f2c84cd782 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -431,16 +431,16 @@ module ActiveRecord rename_column_indexes(table_name, column.name, new_column_name) end - protected + private - def table_structure(table_name) # :nodoc: + def table_structure(table_name) structure = exec_query("PRAGMA table_info(#{quote_table_name(table_name)})", "SCHEMA") raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty? table_structure_with_collation(table_name, structure) end alias column_definitions table_structure - def alter_table(table_name, options = {}) #:nodoc: + def alter_table(table_name, options = {}) altered_table_name = "a#{table_name}" caller = lambda { |definition| yield definition if block_given? } @@ -451,12 +451,12 @@ module ActiveRecord end end - def move_table(from, to, options = {}, &block) #:nodoc: + def move_table(from, to, options = {}, &block) copy_table(from, to, options, &block) drop_table(from) end - def copy_table(from, to, options = {}) #:nodoc: + def copy_table(from, to, options = {}) from_primary_key = primary_key(from) options[:id] = false create_table(to, options) do |definition| @@ -482,7 +482,7 @@ module ActiveRecord options[:rename] || {}) end - def copy_table_indexes(from, to, rename = {}) #:nodoc: + def copy_table_indexes(from, to, rename = {}) indexes(from).each do |index| name = index.name if to == "a#{from}" @@ -505,7 +505,7 @@ module ActiveRecord end end - def copy_table_contents(from, to, columns, rename = {}) #:nodoc: + def copy_table_contents(from, to, columns, rename = {}) column_mappings = Hash[columns.map { |name| [name, name] }] rename.each { |a| column_mappings[a.last] = a.first } from_columns = columns(from).collect(&:name) @@ -518,11 +518,11 @@ module ActiveRecord SELECT #{quoted_from_columns} FROM #{quote_table_name(from)}") end - def sqlite_version + def sqlite_version # :doc: @sqlite_version ||= SQLite3Adapter::Version.new(select_value("select sqlite_version(*)")) end - def translate_exception(exception, message) + def translate_exception(exception, message) # :doc: case exception.message # SQLite 3.8.2 returns a newly formatted error message: # UNIQUE constraint failed: *table_name*.*column_name* @@ -537,7 +537,6 @@ module ActiveRecord end end - private COLLATE_REGEX = /.*\"(\w+)\".*collate\s+\"(\w+)\".*/i.freeze def table_structure_with_collation(table_name, basic_structure) |