aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorBrian Christian <brchristian@gmail.com>2016-02-10 10:10:38 -0800
committerBrian Christian <brchristian@gmail.com>2016-02-10 10:10:38 -0800
commite8aeda2ab39b5d416a72edfa74e0fb17721eb6f9 (patch)
treeea2b76a40f9d9ce3046a9fae3f177b9e4c0b1706 /activerecord
parentc74045cf0771ab51dfeca94b30c447cab6193e60 (diff)
downloadrails-e8aeda2ab39b5d416a72edfa74e0fb17721eb6f9.tar.gz
rails-e8aeda2ab39b5d416a72edfa74e0fb17721eb6f9.tar.bz2
rails-e8aeda2ab39b5d416a72edfa74e0fb17721eb6f9.zip
rename to 'second_to_last' and 'third_to_last'
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb8
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb8
-rw-r--r--activerecord/lib/active_record/querying.rb2
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb24
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb8
5 files changed, 25 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 6927f1fca3..2dca6b612e 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -136,12 +136,12 @@ module ActiveRecord
first_nth_or_last(:forty_two, *args)
end
- def antepenultimate(*args)
- first_nth_or_last(:antepenultimate, *args)
+ def third_to_last(*args)
+ first_nth_or_last(:third_to_last, *args)
end
- def penultimate(*args)
- first_nth_or_last(:penultimate, *args)
+ def second_to_last(*args)
+ first_nth_or_last(:second_to_last, *args)
end
def last(*args)
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 5f3d4c6735..2a9627a474 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -198,13 +198,13 @@ module ActiveRecord
end
# Same as #first except returns only the third-to-last record.
- def antepenultimate(*args)
- @association.antepenultimate(*args)
+ def third_to_last(*args)
+ @association.third_to_last(*args)
end
# Same as #first except returns only the second-to-last record.
- def penultimate(*args)
- @association.penultimate(*args)
+ def second_to_last(*args)
+ @association.second_to_last(*args)
end
# Returns the last record, or the last +n+ records, from the collection.
diff --git a/activerecord/lib/active_record/querying.rb b/activerecord/lib/active_record/querying.rb
index 0a82832f56..5259797223 100644
--- a/activerecord/lib/active_record/querying.rb
+++ b/activerecord/lib/active_record/querying.rb
@@ -1,7 +1,7 @@
module ActiveRecord
module Querying
delegate :find, :take, :take!, :first, :first!, :last, :last!, :exists?, :any?, :many?, to: :all
- delegate :second, :second!, :third, :third!, :fourth, :fourth!, :fifth, :fifth!, :forty_two, :forty_two!, :antepenultimate, :antepenultimate!, :penultimate, :penultimate!, to: :all
+ delegate :second, :second!, :third, :third!, :fourth, :fourth!, :fifth, :fifth!, :forty_two, :forty_two!, :third_to_last, :third_to_last!, :second_to_last, :second_to_last!, to: :all
delegate :first_or_create, :first_or_create!, :first_or_initialize, to: :all
delegate :find_or_create_by, :find_or_create_by!, :find_or_initialize_by, to: :all
delegate :find_by, :find_by!, to: :all
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 90e05dc340..90a6a466fd 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -245,32 +245,32 @@ module ActiveRecord
# Find the third-to-last record.
# If no order is defined it will order by primary key.
#
- # Person.antepenultimate # returns the third-to-last object fetched by SELECT * FROM people
- # Person.offset(3).antepenultimate # returns the third-to-last object from OFFSET 3
- # Person.where(["user_name = :u", { u: user_name }]).antepenultimate
- def antepenultimate
+ # Person.third_to_last # returns the third-to-last object fetched by SELECT * FROM people
+ # Person.offset(3).third_to_last # returns the third-to-last object from OFFSET 3
+ # Person.where(["user_name = :u", { u: user_name }]).third_to_last
+ def third_to_last
find_nth -3
end
- # Same as #antepenultimate but raises ActiveRecord::RecordNotFound if no record
+ # Same as #third_to_last but raises ActiveRecord::RecordNotFound if no record
# is found.
- def antepenultimate!
+ def third_to_last!
find_nth! -3
end
# Find the second-to-last record.
# If no order is defined it will order by primary key.
#
- # Person.penultimate # returns the second-to-last object fetched by SELECT * FROM people
- # Person.offset(3).penultimate # returns the second-to-last object from OFFSET 3
- # Person.where(["user_name = :u", { u: user_name }]).penultimate
- def penultimate
+ # Person.second_to_last # returns the second-to-last object fetched by SELECT * FROM people
+ # Person.offset(3).second_to_last # returns the second-to-last object from OFFSET 3
+ # Person.where(["user_name = :u", { u: user_name }]).second_to_last
+ def second_to_last
find_nth -2
end
- # Same as #penultimate but raises ActiveRecord::RecordNotFound if no record
+ # Same as #second_to_last but raises ActiveRecord::RecordNotFound if no record
# is found.
- def penultimate!
+ def second_to_last!
find_nth! -2
end
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 4e9f7c330a..e975f4fbdd 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -408,13 +408,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
end
assert_no_queries do
- bulbs.antepenultimate()
- bulbs.antepenultimate({})
+ bulbs.third_to_last()
+ bulbs.third_to_last({})
end
assert_no_queries do
- bulbs.penultimate()
- bulbs.penultimate({})
+ bulbs.second_to_last()
+ bulbs.second_to_last({})
end
assert_no_queries do