From 92fb0815ed3cb92ae18ce8c9cf401ee1b74a971d Mon Sep 17 00:00:00 2001 From: Tee Parham Date: Sat, 6 Sep 2014 11:52:26 -0600 Subject: Fix warnings for undefined local variable * Add private method primary_key_for, which more clearly shows that the expected return value is nil when a primary key is not found. --- activerecord/lib/active_record/schema_dumper.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/schema_dumper.rb') diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 4888907f51..b560c58a66 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -105,18 +105,22 @@ HEADER end end + def primary_key_for(table) + if @connection.respond_to?(:pk_and_sequence_for) + pk, _ = @connection.pk_and_sequence_for(table) + return pk if pk + end + return @connection.primary_key(table) if @connection.respond_to?(:primary_key) + nil + end + def table(table, stream) columns = @connection.columns(table) begin tbl = StringIO.new # first dump primary key column - if @connection.respond_to?(:pk_and_sequence_for) - pk, _ = @connection.pk_and_sequence_for(table) - end - if !pk && @connection.respond_to?(:primary_key) - pk = @connection.primary_key(table) - end + pk = primary_key_for(table) tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}" pkcol = columns.detect { |c| c.name == pk } -- cgit v1.2.3