Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
fix find_duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Jul 19, 2017
1 parent c4ce952 commit fb370e6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CHANGELOG
---------

- **1.0.4 - July 19, 2017**
- Fix error in `find_duplicates` method
- **1.0.3 - May 3, 2017**
- Fix error in `or` method
- **1.0.2 - April 13, 2017**
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ If you want to request a new method please raise an issue and we will discuss th


# Credits
Created by Weston Ganger - @westonganger
Created by Weston Ganger - [@westonganger](https://github.com/westonganger)

<a href='https://ko-fi.com/A5071NK' target='_blank'><img height='32' style='border:0px;height:32px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
For any consulting or contract work please contact me via my company website: [Solid Foundation Web Development](https://solidfoundationwebdev.com)

## Similar Libraries Created By Me
- [Rearmed Ruby](https://github.com/westonganger/rearmed-rb)
- [Rearmed JS](https://github.com/westonganger/rearmed_rails)
- [Rearmed CSS](https://github.com/westonganger/rearmed_css)
6 changes: 3 additions & 3 deletions lib/rearmed_rails/monkey_patches/rails/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def self.find_duplicates(*args)
end

if options[:delete][:keep] == :last
duplicates.reverse!
duplicates = duplicates.reverse
end

used = []
duplicates.reject! do |x|
duplicates = duplicates.reject do |x|
attrs = x.attributes.slice(*options[:columns].collect(&:to_s))

if used.include?(attrs)
Expand All @@ -122,7 +122,7 @@ def self.find_duplicates(*args)
if options[:delete][:delete_method].to_sym == :delete
duplicates = self.where(id: duplicates.collect(&:id))

if x.respond_to?(:delete_all!)
if duplicates.respond_to?(:delete_all!)
duplicates.delete_all!
else
duplicates.delete_all
Expand Down
2 changes: 1 addition & 1 deletion lib/rearmed_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RearmedRails
VERSION = "1.0.3"
VERSION = "1.0.4"
end
2 changes: 0 additions & 2 deletions test/tc_rearmed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def test_minitest
end

def test_general_rails
# THE MOST IMPORTANT TESTS HERE WOULD BE dedupe, reset_auto_increment, reset_table

#Post.pluck_to_hash(:name, :category, :id)
#Post.pluck_to_struct(:name, :category, :id)

Expand Down

0 comments on commit fb370e6

Please sign in to comment.