Permalink
Browse files

Remove some ruby -w warnings

This fixes ruby -w warnings not related to redefined methods
or unintialized instance variables.  I don't plan to
make Sequel -w clean, but at least some of the -w warnings have
value and brought up useful issues (unused/unreachable code).

This adds *_w versions of all of the rake spec tasks that run
the specs with -w set, filtering out redefined method, uninitialized
instance variable, and spec usage of == in void context.
  • Loading branch information...
1 parent 537a5c0 commit 645a3c437af5ee871d6c6c03e2858a141b12ee46 @jeremyevans committed Apr 8, 2013
Showing with 163 additions and 162 deletions.
  1. +7 −1 Rakefile
  2. +2 −1 bin/sequel
  3. +2 −0 lib/sequel/adapters/mock.rb
  4. +5 −5 lib/sequel/adapters/postgres.rb
  5. +2 −2 lib/sequel/adapters/shared/mysql.rb
  6. +17 −17 lib/sequel/adapters/shared/postgres.rb
  7. +2 −2 lib/sequel/adapters/sqlite.rb
  8. +3 −3 lib/sequel/adapters/utils/split_alter_table.rb
  9. +1 −1 lib/sequel/connection_pool/threaded.rb
  10. +1 −1 lib/sequel/core.rb
  11. +2 −2 lib/sequel/database/connecting.rb
  12. +2 −2 lib/sequel/database/misc.rb
  13. +1 −1 lib/sequel/database/query.rb
  14. +1 −1 lib/sequel/dataset/actions.rb
  15. +1 −1 lib/sequel/dataset/misc.rb
  16. +1 −1 lib/sequel/dataset/prepared_statements.rb
  17. +1 −2 lib/sequel/dataset/query.rb
  18. +5 −5 lib/sequel/dataset/sql.rb
  19. +1 −1 lib/sequel/extensions/constraint_validations.rb
  20. +2 −2 lib/sequel/extensions/pg_row.rb
  21. +1 −1 lib/sequel/extensions/schema_dumper.rb
  22. +6 −1 lib/sequel/model.rb
  23. +2 −4 lib/sequel/model/associations.rb
  24. +4 −4 lib/sequel/model/base.rb
  25. +1 −1 lib/sequel/plugins/instance_filters.rb
  26. +1 −2 lib/sequel/plugins/many_through_many.rb
  27. +2 −2 lib/sequel/plugins/rcte_tree.rb
  28. +4 −4 lib/sequel/plugins/single_table_inheritance.rb
  29. +1 −1 lib/sequel/plugins/xml_serializer.rb
  30. +1 −1 lib/sequel/sql.rb
  31. +5 −5 spec/adapters/postgres_spec.rb
  32. +1 −1 spec/adapters/sqlite_spec.rb
  33. +8 −9 spec/core/connection_pool_spec.rb
  34. +7 −5 spec/core/database_spec.rb
  35. +5 −3 spec/core/dataset_spec.rb
  36. +2 −1 spec/core/expression_filters_spec.rb
  37. +0 −1 spec/core/object_graph_spec.rb
  38. +1 −1 spec/extensions/association_dependencies_spec.rb
  39. +1 −1 spec/extensions/class_table_inheritance_spec.rb
  40. +5 −5 spec/extensions/composition_spec.rb
  41. +2 −2 spec/extensions/constraint_validations_spec.rb
  42. +1 −1 spec/extensions/core_refinements_spec.rb
  43. +0 −1 spec/extensions/identity_map_spec.rb
  44. +0 −1 spec/extensions/instance_hooks_spec.rb
  45. +0 −1 spec/extensions/json_serializer_spec.rb
  46. +0 −1 spec/extensions/many_through_many_spec.rb
  47. +2 −3 spec/extensions/pg_interval_spec.rb
  48. +15 −15 spec/extensions/pg_row_spec.rb
  49. +2 −2 spec/extensions/rcte_tree_spec.rb
  50. +0 −2 spec/extensions/serialization_spec.rb
  51. +1 −1 spec/extensions/sharding_spec.rb
  52. +5 −5 spec/integration/associations_test.rb
  53. +4 −4 spec/integration/eager_loader_test.rb
  54. +2 −2 spec/integration/model_test.rb
  55. +1 −1 spec/integration/plugin_test.rb
  56. +1 −1 spec/integration/prepared_statement_test.rb
  57. +0 −1 spec/integration/timezone_test.rb
  58. +0 −1 spec/integration/transaction_test.rb
  59. +2 −4 spec/model/associations_spec.rb
  60. +8 −8 spec/model/eager_loading_spec.rb
  61. +0 −1 spec/model/model_spec.rb
View
@@ -129,6 +129,13 @@ begin
spec = lambda do |name, files, d|
lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'lib')
ENV['RUBYLIB'] ? (ENV['RUBYLIB'] += ":#{lib_dir}") : (ENV['RUBYLIB'] = lib_dir)
+
+ desc "#{d} with -w, some warnings filtered"
+ task "#{name}_w" do
+ ENV['RUBYOPT'] ? (ENV['RUBYOPT'] += " -w") : (ENV['RUBYOPT'] = '-w')
+ sh "#{FileUtils::RUBY} -S rake #{name} 2>&1 | egrep -v \"(spec/.*: warning: (possibly )?useless use of == in void context|: warning: instance variable @.* not initialized|: warning: method redefined; discarding old|: warning: previous definition of)|rspec\""
+ end
+
desc d
spec_class.new(name) do |t|
t.send spec_files_meth, files
@@ -201,7 +208,6 @@ desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
STATS_DIRECTORIES = [%w(Code lib/), %w(Spec spec)].map{|name, dir| [ name, "./#{dir}" ] }.select { |name, dir| File.directory?(dir)}
require "./extra/stats"
- verbose = true
CodeStatistics.new(*STATS_DIRECTORIES).to_s
end
View
@@ -17,7 +17,7 @@ load_dirs = []
exclusive_options = []
loggers = []
-opts = OptionParser.new do |opts|
+options = OptionParser.new do |opts|
opts.banner = "Sequel: The Database Toolkit for Ruby"
opts.define_head "Usage: sequel [options] <uri|path> [file]"
opts.separator ""
@@ -107,6 +107,7 @@ opts = OptionParser.new do |opts|
exit
end
end
+opts = options
opts.parse!
db = ARGV.shift
@@ -151,6 +151,8 @@ def initialize(opts={})
if pr = SHARED_ADAPTER_SETUP[opts[:host]]
pr.call(self)
end
+ else
+ @shared_adapter = false
end
self.autoid = opts[:autoid]
self.columns = opts[:columns]
@@ -237,12 +237,12 @@ def convert_infinite_timestamps=(v)
@convert_infinite_timestamps = v
pr = old_pr = Postgres.use_iso_date_format ? TYPE_TRANSLATOR.method(:date) : Sequel.method(:string_to_date)
if v
- pr = lambda do |v|
- case v
+ pr = lambda do |val|
+ case val
when *INFINITE_TIMESTAMP_STRINGS
- infinite_timestamp_value(v)
+ infinite_timestamp_value(val)
else
- old_pr.call(v)
+ old_pr.call(val)
end
end
end
@@ -345,7 +345,7 @@ def copy_into(table, opts={})
conn.put_copy_data(buf)
end
else
- data.each{|buf| conn.put_copy_data(buf)}
+ data.each{|buff| conn.put_copy_data(buff)}
end
rescue Exception => e
conn.put_copy_end("ruby exception occurred while copying data into PostgreSQL")
@@ -203,7 +203,7 @@ def alter_table_op_sql(table, op)
opts.delete(:auto_increment) if op[:auto_increment] == false
"CHANGE COLUMN #{quote_identifier(op[:name])} #{column_definition_sql(opts)}"
when :drop_constraint
- type = case op[:type]
+ case op[:type]
when :primary_key
"DROP PRIMARY KEY"
when :foreign_key
@@ -881,7 +881,7 @@ def insert_values_sql(sql)
def limit_sql(sql)
if l = @opts[:limit]
sql << LIMIT
- literal_append(sql, @opts[:limit])
+ literal_append(sql, l)
end
end
alias delete_limit_sql limit_sql
@@ -665,23 +665,23 @@ def copy_into_sql(table, opts)
# SQL for doing fast table output to stdout.
def copy_table_sql(table, opts)
- if table.is_a?(String)
- return table
- else
- if opts[:options] || opts[:format]
- options = " ("
- options << "FORMAT #{opts[:format]}" if opts[:format]
- options << "#{', ' if opts[:format]}#{opts[:options]}" if opts[:options]
- options << ')'
- end
- table = if table.is_a?(::Sequel::Dataset)
- "(#{table.sql})"
- else
- literal(table)
- end
- return "COPY #{table} TO STDOUT#{options}"
- end
- end
+ if table.is_a?(String)
+ table
+ else
+ if opts[:options] || opts[:format]
+ options = " ("
+ options << "FORMAT #{opts[:format]}" if opts[:format]
+ options << "#{', ' if opts[:format]}#{opts[:options]}" if opts[:options]
+ options << ')'
+ end
+ table = if table.is_a?(::Sequel::Dataset)
+ "(#{table.sql})"
+ else
+ literal(table)
+ end
+ "COPY #{table} TO STDOUT#{options}"
+ end
+ end
# SQL statement to create database function.
def create_function_sql(name, definition, opts={})
@@ -356,8 +356,8 @@ def fetch_rows(sql)
@columns = cols.map{|c| c.first}
result.each do |values|
row = {}
- cols.each do |name,i,type_proc|
- v = values[i]
+ cols.each do |name,id,type_proc|
+ v = values[id]
if type_proc && v
v = type_proc.call(v)
end
@@ -27,9 +27,9 @@ def apply_alter_table(name, ops)
op_groups.last << op
end
- op_groups.each do |ops|
- next if ops.empty?
- alter_table_sql_list(name, ops).each{|sql| execute_ddl(sql)}
+ op_groups.each do |opgs|
+ next if opgs.empty?
+ alter_table_sql_list(name, opgs).each{|sql| execute_ddl(sql)}
remove_cached_schema(name)
end
end
@@ -49,7 +49,7 @@ def all_connections
hold do |c|
sync do
yield c
- @available_connections.each{|c| yield c}
+ @available_connections.each{|conn| yield conn}
end
end
end
View
@@ -369,7 +369,7 @@ def self.transaction(dbs, opts={}, &block)
if rescue_rollback
begin
pr.call
- rescue Sequel::Rollback => e
+ rescue Sequel::Rollback
nil
end
else
@@ -37,7 +37,7 @@ def self.adapter_class(scheme)
# Returns the scheme symbol for the Database class.
def self.adapter_scheme
- @scheme
+ @scheme if defined?(@scheme)
end
# Connects to a database. See Sequel.connect.
@@ -55,7 +55,7 @@ def self.connect(conn_string, opts = {})
c = adapter_class(scheme)
uri_options = c.send(:uri_to_options, uri)
uri.query.split('&').collect{|s| s.split('=')}.each{|k,v| uri_options[k.to_sym] = v if k && !k.empty?} unless uri.query.to_s.strip.empty?
- uri_options.to_a.each{|k,v| uri_options[k] = URI.unescape(v) if v.is_a?(String)}
+ uri_options.to_a.each{|k,v| uri_options[k] = (defined?(URI::DEFAULT_PARSER) ? URI::DEFAULT_PARSER : URI).unescape(v) if v.is_a?(String)}
opts = uri_options.merge(opts).merge!(:orig_opts=>opts.dup, :uri=>conn_string, :adapter=>scheme)
end
when Hash
@@ -306,8 +306,8 @@ def database_specific_error_class(exception, opts)
return klass
end
else
- database_error_regexps.each do |regexp, klass|
- return klass if exception.message =~ regexp
+ database_error_regexps.each do |regexp, klss|
+ return klss if exception.message =~ regexp
end
end
@@ -312,7 +312,7 @@ def input_identifier_meth(ds=nil)
# for this database. Used when parsing metadata so that column symbols are
# returned as expected.
def metadata_dataset
- return @metadata_dataset if @metadata_dataset
+ return @metadata_dataset if defined?(@metadata_dataset) && @metadata_dataset
ds = dataset
ds.identifier_input_method = identifier_input_method_default
ds.identifier_output_method = identifier_output_method_default
@@ -148,7 +148,7 @@ def delete(&block)
def each
if @opts[:graph]
graph_each{|r| yield r}
- elsif row_proc = @row_proc
+ elsif defined?(@row_proc) && (row_proc = @row_proc)
fetch_rows(select_sql){|r| yield row_proc.call(r)}
else
fetch_rows(select_sql){|r| yield r}
@@ -81,7 +81,7 @@ def first_source_alias
when SQL::AliasedExpression
s.aliaz
when Symbol
- sch, table, aliaz = split_symbol(s)
+ _, _, aliaz = split_symbol(s)
aliaz ? aliaz.to_sym : s
else
s
@@ -29,7 +29,7 @@ def call(bind_vars={}, &block)
# Override the given *_sql method based on the type, and
# cache the result of the sql.
def prepared_sql
- return @prepared_sql if @prepared_sql
+ return @prepared_sql if defined?(@prepared_sql) && @prepared_sql
@prepared_args ||= []
@prepared_sql = super
@opts[:sql] = @prepared_sql
@@ -495,7 +495,7 @@ def join_table(type, table, expr=nil, options={}, &block)
using_join = expr.is_a?(Array) && !expr.empty? && expr.all?{|x| x.is_a?(Symbol)}
if using_join && !supports_join_using?
h = {}
- expr.each{|s| h[s] = s}
+ expr.each{|e| h[e] = e}
return join_table(type, table, h, options)
end
@@ -1107,7 +1107,6 @@ def hoist_cte?(ds)
# DB[:items].invert_order([:category, Sequel.desc(:price)]) #=> [Sequel.desc(:category), Sequel.asc(:price)]
def invert_order(order)
return nil unless order
- new_order = []
order.map do |f|
case f
when SQL::OrderedExpression
View
@@ -345,7 +345,7 @@ def #{meth}(*args, &block)
end
end
def_append_methods(PUBLIC_APPEND_METHODS + PRIVATE_APPEND_METHODS)
- private *PRIVATE_APPEND_METHODS
+ private(*PRIVATE_APPEND_METHODS)
# SQL fragment for AliasedExpression
def aliased_expression_sql_append(sql, ae)
@@ -412,11 +412,11 @@ def complex_expression_sql_append(sql, op, args)
when *IS_OPERATORS
r = args.at(1)
if r.nil? || supports_is_true?
- raise(InvalidOperation, 'Invalid argument used for IS operator') unless v = IS_LITERALS[r]
+ raise(InvalidOperation, 'Invalid argument used for IS operator') unless val = IS_LITERALS[r]
sql << PAREN_OPEN
literal_append(sql, args.at(0))
sql << SPACE << op.to_s << SPACE
- sql << v << PAREN_CLOSE
+ sql << val << PAREN_CLOSE
elsif op == :IS
complex_expression_sql_append(sql, :"=", args)
else
@@ -667,7 +667,7 @@ def schema_and_table(table_name, sch=(db.default_schema if db))
sch = sch.to_s if sch
case table_name
when Symbol
- s, t, a = split_symbol(table_name)
+ s, t, _ = split_symbol(table_name)
[s||sch, t]
when SQL::QualifiedIdentifier
[table_name.table.to_s, table_name.column.to_s]
@@ -1195,7 +1195,7 @@ def native_function_name(emulated_function)
# name isn't already qualified.
def qualified_column_name(column, table)
if Symbol === column
- c_table, column, c_alias = split_symbol(column)
+ c_table, column, _ = split_symbol(column)
unless c_table
case table
when Symbol
@@ -357,7 +357,7 @@ def process_generator_validations(table, generator, validations)
when :includes
generator_add_constraint_from_validation(generator, val, Sequel.&(*columns.map{|c| {c => arg}}))
if arg.is_a?(Range)
- if (b = arg.begin).is_a?(Integer) && (e = arg.end).is_a?(Integer)
+ if arg.begin.is_a?(Integer) && arg.end.is_a?(Integer)
validation_type = :includes_int_range
arg = "#{arg.begin}..#{'.' if arg.exclude_end?}#{arg.end}"
else
@@ -106,7 +106,7 @@ class << self
# This is done so that instances of this subclass are
# automatically casted to the database type when literalizing.
def self.subclass(db_type)
- sc = Class.new(self) do
+ Class.new(self) do
@db_type = db_type
end
end
@@ -154,7 +154,7 @@ class << self
# Create a new subclass of this class with the given database
# type and columns.
def self.subclass(db_type, columns)
- sc = Class.new(self) do
+ Class.new(self) do
@db_type = db_type
@columns = columns
end
@@ -149,7 +149,7 @@ def recreate_column(name, schema, gen, options)
# be :type. The other options added should modify that type (e.g. :size). If a
# database type is not recognized, return it as a String type.
def column_schema_to_ruby_type(schema)
- case t = schema[:db_type].downcase
+ case schema[:db_type].downcase
when /\A(medium|small)?int(?:eger)?(?:\((\d+)\))?( unsigned)?\z/o
if !$1 && $2 && $2.to_i >= 10 && $3
# Unsigned integer type with 10 digits can potentially contain values which
View
@@ -114,7 +114,8 @@ class Model
:@typecast_empty_string_to_nil=>nil, :@typecast_on_assignment=>nil,
:@raise_on_typecast_failure=>nil, :@plugins=>:dup, :@setter_methods=>nil,
:@use_after_commit_rollback=>nil, :@fast_pk_lookup_sql=>nil,
- :@fast_instance_delete_sql=>nil}
+ :@fast_instance_delete_sql=>nil, :@default_eager_limit_strategy=>nil,
+ :@db=>nil}
# Regular expression that determines if a method name is normal in the sense that
# it could be used literally in ruby code without using send. Used to
@@ -128,8 +129,12 @@ class Model
@allowed_columns = nil
@db = nil
@db_schema = nil
+ @dataset = nil
@dataset_method_modules = []
+ @default_eager_limit_strategy = nil
@overridable_methods_module = nil
+ @fast_pk_lookup_sql = nil
+ @fast_instance_delete_sql = nil
@plugins = []
@primary_key = :id
@raise_on_save_failure = true
@@ -1030,7 +1030,7 @@ def apply_correlated_subquery_eager_limit_strategy(ds, opts)
oproc = lambda do |x|
case x
when Symbol
- t, c, a = ds.send(:split_symbol, x)
+ t, c, _ = ds.send(:split_symbol, x)
if t && t.to_sym == table
SQL::QualifiedIdentifier.new(dsa, c)
else
@@ -1136,7 +1136,7 @@ def def_many_to_many(opts)
raise(Error, "mismatched number of right keys: #{rcks.inspect} vs #{rcpks.inspect}") unless rcks.length == rcpks.length
end
uses_lcks = opts[:uses_left_composite_keys] = lcks.length > 1
- uses_rcks = opts[:uses_right_composite_keys] = rcks.length > 1
+ opts[:uses_right_composite_keys] = rcks.length > 1
opts[:cartesian_product_number] ||= 1
join_table = (opts[:join_table] ||= opts.default_join_table)
left_key_alias = opts[:left_key_alias] ||= opts.default_associated_key_alias
@@ -1232,7 +1232,6 @@ def def_many_to_one(opts)
raise(Error, "mismatched number of keys: #{cks.inspect} vs #{cpks.inspect}") unless cks.length == cpks.length
end
uses_cks = opts[:uses_composite_keys] = cks.length > 1
- qualify = opts[:qualify] != false
opts[:cartesian_product_number] ||= 0
opts[:dataset] ||= proc do
opts.associated_dataset.where(opts.predicate_keys.zip(cks.map{|k| send(k)}))
@@ -1907,7 +1906,6 @@ def eager_graph_association(ds, model, ta, requirements, r, *associations)
else
alias_base = r[:graph_alias_base]
end
- assoc_name = r[:name]
assoc_table_alias = ds.unused_table_alias(alias_base)
loader = r[:eager_grapher]
if !associations.empty?
Oops, something went wrong.

0 comments on commit 645a3c4

Please sign in to comment.