Skip to content

Commit

Permalink
Fix rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
moiristo committed Nov 27, 2020
1 parent a2f768c commit fe39aab
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
AllCops:
NewCops: enable

Gemspec/RequiredRubyVersion:
Enabled: false

Layout/LineLength:
Enabled: false

Metrics:
Enabled: false

Expand All @@ -13,6 +22,9 @@ Style/Documentation:
Style/AccessModifierDeclarations:
Enabled: false

Style/OptionalBooleanParameter:
Enabled: false

Style/SafeNavigation:
Enabled: false

Expand Down
1 change: 1 addition & 0 deletions deep_cloneable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Gem::Specification.new do |s|
]
s.homepage = 'https://github.com/moiristo/deep_cloneable'
s.licenses = ['MIT']
s.required_ruby_version = '>= 1.9.3'
s.rubygems_version = '3.0.2'
s.summary = 'This gem gives every ActiveRecord::Base object the possibility to do a deep clone.'

Expand Down
5 changes: 3 additions & 2 deletions lib/deep_cloneable/deep_clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ def deep_clone(*args, &block)
association = association.keys.first
end

if conditions_or_deep_associations.is_a?(Hash)
case conditions_or_deep_associations
when Hash
conditions_or_deep_associations = conditions_or_deep_associations.dup
conditions[:if] = conditions_or_deep_associations.delete(:if) if conditions_or_deep_associations[:if]
conditions[:unless] = conditions_or_deep_associations.delete(:unless) if conditions_or_deep_associations[:unless]
elsif conditions_or_deep_associations.is_a?(Array)
when Array
conditions_or_deep_associations = conditions_or_deep_associations.dup
conditions_or_deep_associations.delete_if { |entry| conditions.merge!(entry) if entry.is_a?(Hash) && (entry.key?(:if) || entry.key?(:unless)) }
end
Expand Down
2 changes: 2 additions & 0 deletions test/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class Ownership < ActiveRecord::Base
end

class GoldPiece < ActiveRecord::Base; belongs_to :treasure end

class Matey < ActiveRecord::Base; belongs_to :pirate end

class BattleShip < ActiveRecord::Base; has_many :pirates, :as => :ship end

class Parrot < ActiveRecord::Base
Expand Down
4 changes: 2 additions & 2 deletions test/test_deep_cloneable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def test_should_deep_clone_with_block
end

def test_should_deep_clone_with_preprocessor
deep_clone = @jack.deep_clone(:include => :parrot, preprocessor: lambda { |original, kopy| kopy.cloned_from_id = original.id })
deep_clone = @jack.deep_clone(:include => :parrot, :preprocessor => lambda { |original, kopy| kopy.cloned_from_id = original.id })

assert deep_clone.new_record?
assert deep_clone.save
Expand All @@ -274,7 +274,7 @@ def test_should_deep_clone_with_preprocessor
end

def test_should_deep_clone_with_postprocessor
deep_clone = @jack.deep_clone(:include => :parrot, postprocessor: lambda { |original, kopy| kopy.cloned_from_id = original.id })
deep_clone = @jack.deep_clone(:include => :parrot, :postprocessor => lambda { |original, kopy| kopy.cloned_from_id = original.id })

assert deep_clone.new_record?
assert deep_clone.save
Expand Down
10 changes: 5 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
I18n.enforce_available_locales = true

def load_schema
config = YAML.load(IO.read(File.dirname(__FILE__) + '/database.yml'))
config = YAML.load(IO.read("#{File.dirname(__FILE__)}/database.yml"))

ActiveRecord::Base.logger = if defined?(ActiveSupport::BufferedLogger)
ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + '/debug.log')
ActiveSupport::BufferedLogger.new("#{File.dirname(__FILE__)}/debug.log")
else
ActiveSupport::Logger.new(File.dirname(__FILE__) + '/debug.log')
ActiveSupport::Logger.new("#{File.dirname(__FILE__)}/debug.log")
end

db_adapter = ENV['DB']
Expand All @@ -29,9 +29,9 @@ def load_schema
raise 'No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3.' if db_adapter.nil?

ActiveRecord::Base.establish_connection(config[db_adapter])
load(File.dirname(__FILE__) + '/schema.rb')
load("#{File.dirname(__FILE__)}/schema.rb")
end

load_schema
require File.dirname(__FILE__) + '/../init.rb'
require "#{File.dirname(__FILE__)}/../init.rb"
require 'models'

0 comments on commit fe39aab

Please sign in to comment.