aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2012-08-06 00:27:56 +0200
committerXavier Noria <fxn@hashref.com>2012-08-06 00:30:02 +0200
commit447b6a4e678ab1618bdcd130e30c288b0a25297a (patch)
tree6d9cb3417996517a5b237d3950c25ab32a5db098 /activerecord/lib/active_record
parent6126f02cf903fa206b11d2dc2eeb5f197a29b965 (diff)
downloadrails-447b6a4e678ab1618bdcd130e30c288b0a25297a.tar.gz
rails-447b6a4e678ab1618bdcd130e30c288b0a25297a.tar.bz2
rails-447b6a4e678ab1618bdcd130e30c288b0a25297a.zip
removes usage of Object#in? from the code base (the method remains defined by Active Support)
Selecting which key extensions to include in active_support/rails made apparent the systematic usage of Object#in? in the code base. After some discussion in https://github.com/rails/rails/commit/5ea6b0df9a36d033f21b52049426257a4637028d we decided to remove it and use plain Ruby, which seems enough for this particular idiom. In this commit the refactor has been made case by case. Sometimes include? is the natural alternative, others a simple || is the way you actually spell the condition in your head, others a case statement seems more appropriate. I have chosen the one I liked the most in each case.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/association.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_one_association.rb21
-rw-r--r--activerecord/lib/active_record/inheritance.rb2
-rw-r--r--activerecord/lib/active_record/railties/databases.rake1
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb2
5 files changed, 15 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index 4db7038d2e..9f47e7e631 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -176,7 +176,7 @@ module ActiveRecord
def creation_attributes
attributes = {}
- if reflection.macro.in?([:has_one, :has_many]) && !options[:through]
+ if (reflection.macro == :has_one || reflection.macro == :has_many) && !options[:through]
attributes[reflection.foreign_key] = owner[reflection.active_record_primary_key]
if reflection.options[:as]
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index c5aed6e26a..191c4e8e39 100644
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -51,16 +51,19 @@ module ActiveRecord
end
def remove_target!(method)
- if method.in?([:delete, :destroy])
- target.send(method)
- else
- nullify_owner_attributes(target)
+ case method
+ when :delete
+ target.delete
+ when :destroy
+ target.destroy
+ else
+ nullify_owner_attributes(target)
- if target.persisted? && owner.persisted? && !target.save
- set_owner_attributes(target)
- raise RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " +
- "The record failed to save when after its foreign key was set to nil."
- end
+ if target.persisted? && owner.persisted? && !target.save
+ set_owner_attributes(target)
+ raise RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " +
+ "The record failed to save when after its foreign key was set to nil."
+ end
end
end
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb
index 7d759c1048..04fff99a6e 100644
--- a/activerecord/lib/active_record/inheritance.rb
+++ b/activerecord/lib/active_record/inheritance.rb
@@ -55,7 +55,7 @@ module ActiveRecord
end
sup = active_record_super
- if sup.in?([Base, Model]) || sup.abstract_class?
+ if sup == Base || sup == Model || sup.abstract_class?
self
else
sup.base_class
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 6bb0c39b79..e0659700b6 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -1,4 +1,3 @@
-require 'active_support/core_ext/object/inclusion'
require 'active_record'
db_namespace = namespace :db do
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index fb3dfc2730..b41cc68b6a 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -115,7 +115,7 @@ module ActiveRecord
end
def local_database?(configuration)
- configuration['host'].in?(LOCAL_HOSTS) || configuration['host'].blank?
+ configuration['host'].blank? || LOCAL_HOSTS.include?(configuration['host'])
end
end
end