From 54be209daa8d82b73f864cedcb76ca8429535c68 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Wed, 25 Jun 2008 17:49:04 +0800 Subject: [PATCH] ActionPack: Don't use Symbol#to_proc in framework code. --- .../assertions/selector_assertions.rb | 2 +- actionpack/lib/action_controller/base.rb | 12 ++++++------ actionpack/lib/action_controller/cgi_ext/cookie.rb | 2 +- actionpack/lib/action_controller/filters.rb | 16 ++++++++++++---- actionpack/lib/action_view/helpers/tag_helper.rb | 2 +- actionpack/lib/action_view/template_handlers.rb | 2 +- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/actionpack/lib/action_controller/assertions/selector_assertions.rb b/actionpack/lib/action_controller/assertions/selector_assertions.rb index d3594e7..c8bbde9 100644 --- a/actionpack/lib/action_controller/assertions/selector_assertions.rb +++ b/actionpack/lib/action_controller/assertions/selector_assertions.rb @@ -282,7 +282,7 @@ module ActionController end elsif match_with = equals[:html] matches.delete_if do |match| - html = match.children.map(&:to_s).join + html = match.children.map { |child| child.to_s }.join html.strip! unless NO_STRIP.include?(match.name) unless match_with.is_a?(Regexp) ? (html =~ match_with) : (html == match_with.to_s) content_mismatch ||= build_message(message, " expected but was\n.", match_with, html) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index bf34edc..4f5ca92 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -402,7 +402,7 @@ module ActionController #:nodoc: # More methods can be hidden using hide_actions. def hidden_actions unless read_inheritable_attribute(:hidden_actions) - write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map(&:to_s)) + write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map { |m| m.to_s }) end read_inheritable_attribute(:hidden_actions) @@ -410,12 +410,12 @@ module ActionController #:nodoc: # Hide each of the given methods from being callable as actions. def hide_action(*names) - write_inheritable_attribute(:hidden_actions, hidden_actions | names.map(&:to_s)) + write_inheritable_attribute(:hidden_actions, hidden_actions | names.map { |name| name.to_s }) end - ## View load paths determine the bases from which template references can be made. So a call to - ## render("test/template") will be looked up in the view load paths array and the closest match will be - ## returned. + # View load paths determine the bases from which template references can be made. So a call to + # render("test/template") will be looked up in the view load paths array and the closest match will be + # returned. def view_paths @view_paths || superclass.view_paths end @@ -1183,7 +1183,7 @@ module ActionController #:nodoc: end def self.action_methods - @action_methods ||= Set.new(public_instance_methods.map(&:to_s)) - hidden_actions + @action_methods ||= Set.new(public_instance_methods.map { |m| m.to_s }) - hidden_actions end def add_variables_to_assigns diff --git a/actionpack/lib/action_controller/cgi_ext/cookie.rb b/actionpack/lib/action_controller/cgi_ext/cookie.rb index 009ddd1..301f267 100644 --- a/actionpack/lib/action_controller/cgi_ext/cookie.rb +++ b/actionpack/lib/action_controller/cgi_ext/cookie.rb @@ -36,7 +36,7 @@ class CGI #:nodoc: @path = nil else @name = name['name'] - @value = (name['value'].kind_of?(String) ? [name['value']] : Array(name['value'])).delete_if(&:blank?) + @value = (name['value'].kind_of?(String) ? [name['value']] : Array(name['value'])).delete_if { |v| v.blank? } @domain = name['domain'] @expires = name['expires'] @secure = name['secure'] || false diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb index 60d92d9..f265d95 100644 --- a/actionpack/lib/action_controller/filters.rb +++ b/actionpack/lib/action_controller/filters.rb @@ -366,9 +366,9 @@ module ActionController #:nodoc: def included_in_action?(controller, options) if options[:only] - Array(options[:only]).map(&:to_s).include?(controller.action_name) + Array(options[:only]).map { |o| o.to_s }.include?(controller.action_name) elsif options[:except] - !Array(options[:except]).map(&:to_s).include?(controller.action_name) + !Array(options[:except]).map { |o| o.to_s }.include?(controller.action_name) else true end @@ -545,13 +545,21 @@ module ActionController #:nodoc: # Returns all the before filters for this class and all its ancestors. # This method returns the actual filter that was assigned in the controller to maintain existing functionality. def before_filters #:nodoc: - filter_chain.select(&:before?).map(&:method) + filters = [] + for filter in filter_chain + filters << filter.method if filter.before? + end + filters end # Returns all the after filters for this class and all its ancestors. # This method returns the actual filter that was assigned in the controller to maintain existing functionality. def after_filters #:nodoc: - filter_chain.select(&:after?).map(&:method) + filters = [] + for filter in filter_chain + filters << filter.method if filter.after? + end + filters end end diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index aeafd39..4cf1c2d 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -10,7 +10,7 @@ module ActionView include ERB::Util BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple).to_set - BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym)) + BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map { |attr| attr.to_sym }) # Returns an empty HTML tag of type +name+ which by default is XHTML # compliant. Set +open+ to true to create an open tag compatible diff --git a/actionpack/lib/action_view/template_handlers.rb b/actionpack/lib/action_view/template_handlers.rb index 1471e99..328a16c 100644 --- a/actionpack/lib/action_view/template_handlers.rb +++ b/actionpack/lib/action_view/template_handlers.rb @@ -31,7 +31,7 @@ module ActionView #:nodoc: end def template_handler_extensions - @@template_handlers.keys.map(&:to_s).sort + @@template_handlers.keys.map { |k| k.to_s }.sort end def register_default_template_handler(extension, klass) -- 1.5.6 From 3523954f9bdc564312bf1b7ec68e843228d5084f Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Wed, 25 Jun 2008 17:59:41 +0800 Subject: [PATCH] ActiveRecord: Don't use Symbol#to_proc. --- activerecord/lib/active_record/associations.rb | 4 ++-- .../associations/association_collection.rb | 2 +- .../associations/has_many_association.rb | 4 ++-- .../lib/active_record/attribute_methods.rb | 6 +++--- activerecord/lib/active_record/base.rb | 6 +++--- .../abstract/schema_statements.rb | 2 +- .../connection_adapters/postgresql_adapter.rb | 4 ++-- .../connection_adapters/sqlite_adapter.rb | 2 +- activerecord/lib/active_record/fixtures.rb | 4 ++-- activerecord/lib/active_record/migration.rb | 8 ++++---- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index db99b71..2ab881b 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1141,7 +1141,7 @@ module ActiveRecord end define_method("#{reflection.name.to_s.singularize}_ids") do - send(reflection.name).map(&:id) + send(reflection.name).map { |record| record.id } end end @@ -1483,7 +1483,7 @@ module ActiveRecord sql << " FROM #{connection.quote_table_name table_name} " if is_distinct - sql << distinct_join_associations.collect(&:association_join).join + sql << distinct_join_associations.map { |assoc| assoc.association_join }.join add_joins!(sql, options, scope) end diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 52d2a98..11f93ac 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -14,7 +14,7 @@ module ActiveRecord # If using a custom finder_sql, scan the entire collection. if @reflection.options[:finder_sql] expects_array = args.first.kind_of?(Array) - ids = args.flatten.compact.uniq.map(&:to_i) + ids = args.flatten.compact.uniq.map { |arg| arg.to_i } if ids.size == 1 id = ids.first diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 295beb2..7b16b8f 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -53,9 +53,9 @@ module ActiveRecord def delete_records(records) case @reflection.options[:dependent] when :destroy - records.each(&:destroy) + records.each { |r| r.destroy } when :delete_all - @reflection.klass.delete(records.map(&:id)) + @reflection.klass.delete(records.map { |record| record.id }) else ids = quoted_record_ids(records) @reflection.klass.update_all( diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index fab16a4..c1c00b7 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -99,8 +99,8 @@ module ActiveRecord def instance_method_already_implemented?(method_name) method_name = method_name.to_s return true if method_name =~ /^id(=$|\?$|$)/ - @_defined_class_methods ||= ancestors.first(ancestors.index(ActiveRecord::Base)).sum([]) { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) }.map(&:to_s).to_set - @@_defined_activerecord_methods ||= (ActiveRecord::Base.public_instance_methods(false) | ActiveRecord::Base.private_instance_methods(false) | ActiveRecord::Base.protected_instance_methods(false)).map(&:to_s).to_set + @_defined_class_methods ||= ancestors.first(ancestors.index(ActiveRecord::Base)).sum([]) { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) }.map { |method| method.to_s }.to_set + @@_defined_activerecord_methods ||= (ActiveRecord::Base.public_instance_methods(false) | ActiveRecord::Base.private_instance_methods(false) | ActiveRecord::Base.protected_instance_methods(false)).map { |method| method.to_s }.to_set raise DangerousAttributeError, "#{method_name} is defined by ActiveRecord" if @@_defined_activerecord_methods.include?(method_name) @_defined_class_methods.include?(method_name) end @@ -118,7 +118,7 @@ module ActiveRecord # with datatype :datetime, :timestamp, :time, :date are cached. def cached_attributes @cached_attributes ||= - columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map(&:name).to_set + columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map{ |col| col.name }.to_set end # Returns +true+ if the provided attribute is being cached. diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 021aaf4..842d123 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -895,7 +895,7 @@ module ActiveRecord #:nodoc: # To start from an all-closed default and enable attributes as needed, # have a look at +attr_accessible+. def attr_protected(*attributes) - write_inheritable_attribute("attr_protected", Set.new(attributes.map(&:to_s)) + (protected_attributes || [])) + write_inheritable_attribute("attr_protected", Set.new(attributes.map { |a| a.to_s }) + (protected_attributes || [])) end # Returns an array of all the attributes that have been protected from mass-assignment. @@ -928,7 +928,7 @@ module ActiveRecord #:nodoc: # customer.credit_rating = "Average" # customer.credit_rating # => "Average" def attr_accessible(*attributes) - write_inheritable_attribute("attr_accessible", Set.new(attributes.map(&:to_s)) + (accessible_attributes || [])) + write_inheritable_attribute("attr_accessible", Set.new(attributes.map { |a| a.to_s }) + (accessible_attributes || [])) end # Returns an array of all the attributes that have been made accessible to mass-assignment. @@ -938,7 +938,7 @@ module ActiveRecord #:nodoc: # Attributes listed as readonly can be set for a new record, but will be ignored in database updates afterwards. def attr_readonly(*attributes) - write_inheritable_attribute("attr_readonly", Set.new(attributes.map(&:to_s)) + (readonly_attributes || [])) + write_inheritable_attribute("attr_readonly", Set.new(attributes.map { |a| a.to_s }) + (readonly_attributes || [])) end # Returns an array of all the attributes that have been specified as readonly. 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 7d8530e..4f427df 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -334,7 +334,7 @@ module ActiveRecord version = version.to_i sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name) - migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i) + migrated = select_values("SELECT version FROM #{sm_table}").map { |v| v.to_i } versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename| filename.split('/').last.split('_').first.to_i end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 361d177..f62d0ea 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -810,7 +810,7 @@ module ActiveRecord # Construct a clean list of column names from the ORDER BY clause, removing # any ASC/DESC modifiers order_columns = order_by.split(',').collect { |s| s.split.first } - order_columns.delete_if &:blank? + order_columns.delete_if { |col| col.blank? } order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" } # Return a DISTINCT ON() clause that's distinct on the columns we want but includes @@ -826,7 +826,7 @@ module ActiveRecord def add_order_by_for_association_limiting!(sql, options) #:nodoc: return sql if options[:order].blank? - order = options[:order].split(',').collect { |s| s.strip }.reject(&:blank?) + order = options[:order].split(',').collect { |s| s.strip }.reject { |s| s.blank?} order.map! { |s| 'DESC' if s =~ /\bdesc$/i } order = order.zip((0...order.size).to_a).map { |s,i| "id_list.alias_#{i} #{s}" }.join(', ') diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 51cfd10..afd9e71 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -326,7 +326,7 @@ module ActiveRecord name = name[5..-1] end - to_column_names = columns(to).map(&:name) + to_column_names = columns(to).map { |col| col.name } columns = index.columns.map {|c| rename[c] || c }.select do |column| to_column_names.include?(column) end diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index e19614e..80484b0 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -684,7 +684,7 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash) end def column_names - @column_names ||= @connection.columns(@table_name).collect(&:name) + @column_names ||= @connection.columns(@table_name).collect { |col| col.name } end def read_fixture_files @@ -898,7 +898,7 @@ module Test #:nodoc: def uses_transaction(*methods) @uses_transaction = [] unless defined?(@uses_transaction) - @uses_transaction.concat methods.map(&:to_s) + @uses_transaction.concat methods.map { |m| m.to_s } end def uses_transaction?(method) diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index e095b3c..4676951 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -321,7 +321,7 @@ module ActiveRecord end def method_missing(method, *arguments, &block) - arg_list = arguments.map(&:inspect) * ', ' + arg_list = arguments.map { |arg| arg.inspect } * ', ' say_with_time "#{method}(#{arg_list})" do unless arguments.empty? || method == :execute @@ -372,7 +372,7 @@ module ActiveRecord def current_version version = Base.connection.select_values( "SELECT version FROM #{schema_migrations_table_name}" - ).map(&:to_i).max rescue nil + ).map { |v| v.to_i }.max rescue nil version || 0 end @@ -462,7 +462,7 @@ module ActiveRecord end end - migrations = migrations.sort_by(&:version) + migrations = migrations.sort_by { |m| m.version } down? ? migrations.reverse : migrations end end @@ -474,7 +474,7 @@ module ActiveRecord def migrated sm_table = self.class.schema_migrations_table_name - Base.connection.select_values("SELECT version FROM #{sm_table}").map(&:to_i).sort + Base.connection.select_values("SELECT version FROM #{sm_table}").map { |v| v.to_i }.sort end private -- 1.5.6 From f82d233919448cee4bd446386542267c09728de7 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Wed, 25 Jun 2008 18:04:56 +0800 Subject: [PATCH] ActiveSupport: Don't use Symbol#to_proc. --- .../core_ext/module/introspection.rb | 2 +- .../core_ext/object/instance_variables.rb | 4 ++-- activesupport/lib/active_support/dependencies.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/module/introspection.rb b/activesupport/lib/active_support/core_ext/module/introspection.rb index 40bbebb..bb894ec 100644 --- a/activesupport/lib/active_support/core_ext/module/introspection.rb +++ b/activesupport/lib/active_support/core_ext/module/introspection.rb @@ -70,6 +70,6 @@ class Module # Returns the names of the constants defined locally rather than the # constants themselves. See local_constants. def local_constant_names - local_constants.map(&:to_s) + local_constants.map { |c| c.to_s } end end diff --git a/activesupport/lib/active_support/core_ext/object/instance_variables.rb b/activesupport/lib/active_support/core_ext/object/instance_variables.rb index 9f1d4ed..0b758ab 100644 --- a/activesupport/lib/active_support/core_ext/object/instance_variables.rb +++ b/activesupport/lib/active_support/core_ext/object/instance_variables.rb @@ -35,7 +35,7 @@ class Object # C.new(0, 1).instance_variable_names # => ["@y", "@x"] if RUBY_VERSION >= '1.9' def instance_variable_names - instance_variables.map(&:to_s) + instance_variables.map { |var| var.to_s } end else alias_method :instance_variable_names, :instance_variables @@ -68,7 +68,7 @@ class Object def copy_instance_variables_from(object, exclude = []) #:nodoc: exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables - vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s) + vars = object.instance_variables.map { |var| var.to_s } - exclude.map { |var| var.to_s } vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) } end end diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 7a8c4d0..3dde5a2 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -387,7 +387,7 @@ module ActiveSupport #:nodoc: ensure # Remove the stack frames that we added. if defined?(watch_frames) && ! watch_frames.blank? - frame_ids = watch_frames.collect(&:object_id) + frame_ids = watch_frames.collect { |frame| frame.object_id } constant_watch_stack.delete_if do |watch_frame| frame_ids.include? watch_frame.object_id end @@ -437,7 +437,7 @@ module ActiveSupport #:nodoc: protected def log_call(*args) if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER && log_activity - arg_str = args.collect(&:inspect) * ', ' + arg_str = args.map { |arg| arg.inspect } * ', ' /in `([a-z_\?\!]+)'/ =~ caller(1).first selector = $1 || '' log "called #{selector}(#{arg_str})" -- 1.5.6 From 30522db35dd2d385408dd317d9f099ae43f546fb Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Wed, 25 Jun 2008 18:07:03 +0800 Subject: [PATCH] Railties: Don't use Symbol#to_proc. --- railties/builtin/rails_info/rails/info.rb | 2 +- railties/lib/rails/gem_dependency.rb | 2 +- railties/lib/rails/plugin/loader.rb | 2 +- railties/lib/rails/plugin/locator.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/railties/builtin/rails_info/rails/info.rb b/railties/builtin/rails_info/rails/info.rb index 4cbd2cc..5968724 100644 --- a/railties/builtin/rails_info/rails/info.rb +++ b/railties/builtin/rails_info/rails/info.rb @@ -3,7 +3,7 @@ module Rails mattr_accessor :properties class << (@@properties = []) def names - map &:first + map { |a| a.first } end def value_for(property_name) diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index f8d9784..5c1f243 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -48,7 +48,7 @@ module Rails all_dependencies = specification.dependencies.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements) end - all_dependencies += all_dependencies.map(&:dependencies).flatten + all_dependencies += all_dependencies.map { |dep| dep.dependencies }.flatten all_dependencies.uniq end diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 948d497..8edd648 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -131,7 +131,7 @@ module Rails # so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is # non empty, we load the named plugins in the order specified. def registered_plugin_names - configuration.plugins ? configuration.plugins.map(&:to_s) : nil + configuration.plugins ? configuration.plugins.map { |p| p.to_s } : nil end def loaded?(plugin_name) diff --git a/railties/lib/rails/plugin/locator.rb b/railties/lib/rails/plugin/locator.rb index 79c07fc..559cc90 100644 --- a/railties/lib/rails/plugin/locator.rb +++ b/railties/lib/rails/plugin/locator.rb @@ -25,7 +25,7 @@ module Rails end def plugin_names - plugins.map(&:name) + plugins.map { |p| p.name } end end -- 1.5.6