Skip to content

Commit

Permalink
Fix new version offences
Browse files Browse the repository at this point in the history
  • Loading branch information
ssnickolay committed Oct 31, 2021
1 parent d5d054f commit 6027473
Show file tree
Hide file tree
Showing 26 changed files with 48 additions and 59 deletions.
9 changes: 5 additions & 4 deletions .rubocop.yml
@@ -1,6 +1,6 @@
require:
# add after moving docs to another tool
- 'standard/cop/semantic_blocks'
- 'standard/cop/block_single_line_braces'
- 'rubocop-md'

inherit_gem:
Expand All @@ -19,10 +19,11 @@ AllCops:
Markdown:
WarnInvalid: true

Standard/SemanticBlocks:
Enabled: false

Lint/Void:
Exclude:
- 'docs/README.md'
- 'README.md'

Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/**/*'
5 changes: 1 addition & 4 deletions docs/.rubocop.yml
Expand Up @@ -8,11 +8,8 @@ Lint/Void:
Metrics/AbcSize:
Enabled: false

Standard/SemanticBlocks:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/LineLength:
Layout/LineLength:
Enabled: false
2 changes: 1 addition & 1 deletion docs/parameters.md
Expand Up @@ -75,7 +75,7 @@ class UserCloner < Clowne::Cloner
include_association :profile, params: Proc.new do |params, user|
{
name: params[:profile][:name],
email: user.email,
email: user.email
}
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/clowne.rb
Expand Up @@ -9,11 +9,10 @@
# Declarative models cloning
module Clowne
# List of built-in adapters
# rubocop:disable Layout/AlignHash
ADAPTERS = {
base: "Base",
base: "Base",
active_record: "ActiveRecord",
sequel: "Sequel",
sequel: "Sequel"
}.freeze
# rubocop:enable Layout/AlignHash

Expand Down
2 changes: 1 addition & 1 deletion lib/clowne/adapters/active_record/associations.rb
Expand Up @@ -15,7 +15,7 @@ module Associations
belongs_to: BelongsTo,
has_one: HasOne,
has_many: HasMany,
has_and_belongs_to_many: HABTM,
has_and_belongs_to_many: HABTM
}.freeze

# Returns an association cloner class for reflection
Expand Down
Expand Up @@ -5,7 +5,6 @@ module Adapters # :nodoc: all
class ActiveRecord
module Associations
class BelongsTo < Base
# rubocop: disable Metrics/MethodLength
def call(record)
child = association
return record unless child
Expand Down
1 change: 0 additions & 1 deletion lib/clowne/adapters/active_record/associations/has_one.rb
Expand Up @@ -5,7 +5,6 @@ module Adapters # :nodoc: all
class ActiveRecord
module Associations
class HasOne < Base
# rubocop: disable Metrics/MethodLength
def call(record)
child = association
return record unless child
Expand Down
1 change: 0 additions & 1 deletion lib/clowne/adapters/active_record/resolvers/association.rb
Expand Up @@ -8,7 +8,6 @@ class UnknownAssociation < StandardError; end

class Association
class << self
# rubocop: disable Metrics/ParameterLists
def call(source, record, declaration, adapter:, params:, **_options)
reflection = source.class.reflections[declaration.name.to_s]

Expand Down
2 changes: 1 addition & 1 deletion lib/clowne/adapters/sequel/associations.rb
Expand Up @@ -13,7 +13,7 @@ module Associations
SEQUEL_2_CLONER = {
one_to_one: OneToOne,
one_to_many: OneToMany,
many_to_many: ManyToMany,
many_to_many: ManyToMany
}.freeze

# Returns an association cloner class for reflection
Expand Down
1 change: 0 additions & 1 deletion lib/clowne/adapters/sequel/resolvers/association.rb
Expand Up @@ -6,7 +6,6 @@ class Sequel
module Resolvers
class Association
class << self
# rubocop: disable Metrics/ParameterLists
def call(source, record, declaration, adapter:, params:, **_options)
with_clonable(source, record, declaration) do
reflection = source.class.association_reflections[declaration.name.to_sym]
Expand Down
2 changes: 1 addition & 1 deletion lib/clowne/cloner.rb
Expand Up @@ -8,6 +8,7 @@

module Clowne # :nodoc: all
class UnprocessableSourceError < StandardError; end

class ConfigurationError < StandardError; end

class Cloner
Expand Down Expand Up @@ -43,7 +44,6 @@ def register_trait(name, block)
@traits[name].extend_with(block)
end

# rubocop: disable Metrics/AbcSize, Metrics/MethodLength
def call(object, **options, &block)
raise(UnprocessableSourceError, "Nil is not cloneable object") if object.nil?

Expand Down
2 changes: 1 addition & 1 deletion lib/clowne/declarations.rb
Expand Up @@ -8,7 +8,7 @@ module Declarations # :nodoc:
module_function

def add(id, declaration = nil, &block)
declaration = block if block_given?
declaration = block if block

if declaration.is_a?(Class)
DSL.send(:define_method, id) do |*args, **hargs, &inner_block|
Expand Down
2 changes: 1 addition & 1 deletion lib/clowne/declarations/trait.rb
Expand Up @@ -17,7 +17,7 @@ def compiled
@compiled = compile
end

alias declarations compiled
alias_method :declarations, :compiled

def dup
self.class.new.tap do |duped|
Expand Down
2 changes: 1 addition & 1 deletion lib/clowne/ext/yield_self_then.rb
Expand Up @@ -11,7 +11,7 @@ def yield_self
end
end

alias then yield_self
alias_method :then, :yield_self
end

# See https://github.com/jruby/jruby/issues/5220
Expand Down
1 change: 0 additions & 1 deletion lib/clowne/resolvers/init_as.rb
Expand Up @@ -3,7 +3,6 @@
module Clowne
class Resolvers
module InitAs # :nodoc: all
# rubocop: disable Metrics/ParameterLists
def self.call(source, _record, declaration, params:, adapter:, **_options)
adapter.init_record(declaration.block.call(source, **params))
end
Expand Down
1 change: 0 additions & 1 deletion lib/clowne/rspec/clone_association.rb
Expand Up @@ -20,7 +20,6 @@ def initialize(name, options)
extract_options! options
end

# rubocop: disable Metrics/AbcSize
def match(expected, _actual)
@actual = plan.declarations
.find { |key, decl| key == :association && decl.name == expected }
Expand Down
2 changes: 1 addition & 1 deletion spec/clowne/adapters/base/association_spec.rb
Expand Up @@ -71,7 +71,7 @@
context "with record" do
let(:custom_declaration_params) do
{
params: ->(params, parent) { params.merge(some_stuff: "ಠᴗಠ", parent: parent) },
params: ->(params, parent) { params.merge(some_stuff: "ಠᴗಠ", parent: parent) }
}
end

Expand Down
28 changes: 14 additions & 14 deletions spec/clowne/cloner_spec.rb
Expand Up @@ -33,21 +33,21 @@
let(:expected_plan) do
[
[:association, Clowne::Declarations::IncludeAssociation, {
name: :comments, scope: nil, options: {},
},],
name: :comments, scope: nil, options: {}
}],
[:association, Clowne::Declarations::IncludeAssociation, {
name: :posts,
scope: :some_scope,
options: {clone_with: "AnotherClonerClass"},
},],
options: {clone_with: "AnotherClonerClass"}
}],
[:association, Clowne::Declarations::IncludeAssociation, {
name: :tags,
scope: nil,
options: {clone_with: "AnotherCloner2Class"},
},],
options: {clone_with: "AnotherCloner2Class"}
}],
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[title description]}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 1 }}],
[:after_persist, Clowne::Declarations::AfterPersist, {block: proc { 2 + 2 }}],
[:after_persist, Clowne::Declarations::AfterPersist, {block: proc { 2 + 2 }}]
]
end

Expand All @@ -67,19 +67,19 @@
[:association, Clowne::Declarations::IncludeAssociation, {
name: :posts,
scope: :some_scope,
options: {clone_with: "AnotherClonerClass"},
},],
options: {clone_with: "AnotherClonerClass"}
}],
[:association, Clowne::Declarations::IncludeAssociation, {
name: :tags,
scope: nil,
options: {clone_with: "AnotherCloner2Class"},
},],
options: {clone_with: "AnotherCloner2Class"}
}],
[:association, Clowne::Declarations::IncludeAssociation, {
name: :brands, scope: nil, options: {},
},],
name: :brands, scope: nil, options: {}
}],
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[title description]}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 1 }}],
[:after_persist, Clowne::Declarations::AfterPersist, {block: proc { 2 + 2 }}],
[:after_persist, Clowne::Declarations::AfterPersist, {block: proc { 2 + 2 }}]
]
end

Expand Down
1 change: 0 additions & 1 deletion spec/clowne/integrations/adapter_lifecycle_spec.rb
Expand Up @@ -26,7 +26,6 @@ class PostCloner < Clowne::Cloner; end
end

shared_examples "pass adapter" do
# rubocop:disable Layout/MultilineMethodCallIndentation
it "clones topic" do
expect do
operation.persist
Expand Down
1 change: 0 additions & 1 deletion spec/clowne/integrations/after_persist_spec.rb
Expand Up @@ -50,7 +50,6 @@ class ImgCloner < Clowne::Cloner
and we need to update the cloned topic with the cloned image' do
subject(:operation) { AR::TopicCloner.call(topic) }

# rubocop:disable Layout/MultilineMethodCallIndentation
it "clone and use cloned image" do
expect do
operation.persist
Expand Down
14 changes: 7 additions & 7 deletions spec/clowne/planner_spec.rb
Expand Up @@ -32,7 +32,7 @@
is_expected.to match_declarations(
[
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[foo bar]}],
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[baz]}],
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[baz]}]
]
)
end
Expand All @@ -54,7 +54,7 @@
is_expected.to match_declarations(
[
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[foo]}],
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[bar]}],
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[bar]}]
]
)
end
Expand All @@ -73,7 +73,7 @@
is_expected.to match_declarations(
[
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 1 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 2 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 2 }}]
]
)
end
Expand Down Expand Up @@ -105,7 +105,7 @@
[
[:association, Clowne::Declarations::IncludeAssociation, {name: :users}],
[:association, Clowne::Declarations::IncludeAssociation, {name: :posts}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 1 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 1 }}]
]
)
end
Expand All @@ -120,7 +120,7 @@
[:association, Clowne::Declarations::IncludeAssociation, {name: :users}],
[:association, Clowne::Declarations::IncludeAssociation, {name: :brands}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 1 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 2 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 2 }}]
]
)
end
Expand All @@ -136,7 +136,7 @@
[:association, Clowne::Declarations::IncludeAssociation, {name: :brands}],
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[extra data meta]}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 1 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 2 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 2 }}]
]
)
end
Expand Down Expand Up @@ -166,7 +166,7 @@
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[extra data meta]}],
[:nullify, Clowne::Declarations::Nullify, {attributes: %i[files_cache]}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 1 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 2 }}],
[:finalize, Clowne::Declarations::Finalize, {block: proc { 1 + 2 }}]
]
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/clowne/utils/params_spec.rb
Expand Up @@ -3,7 +3,7 @@
let(:params) do
{
profile: {data: {name: "Robin"}},
rating: 10,
rating: 10
}
end
let(:permitted_params) { subject.permit(params: params) }
Expand Down
8 changes: 4 additions & 4 deletions spec/clowne/utils/plan_spec.rb
Expand Up @@ -23,7 +23,7 @@
[:a, "value_2"],
[:b, "item_1"],
[:b, "item_2"],
[:c, "scalar_1"],
[:c, "scalar_1"]
]
)

Expand All @@ -37,15 +37,15 @@
[:a, "value_2"],
[:b, "item_1"],
[:b, "item_2"],
[:c, "scalar_1"],
[:c, "scalar_1"]
]
)

expect(subject.declarations(true)).to eq(
[
[:a, "value_2"],
[:b, "item_1"],
[:b, "item_2"],
[:b, "item_2"]
]
)

Expand All @@ -55,7 +55,7 @@
[
[:a, "value_2"],
[:b, "item_1"],
[:b, "item_2"],
[:b, "item_2"]
]
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -12,14 +12,14 @@

begin
require "pry-byebug"
rescue LoadError # rubocop:disable Lint/HandleExceptions
rescue LoadError
end

%w[active_record sequel].each do |orm|
require_relative "./support/#{orm}/initializer.rb"
end

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }

Clowne.default_adapter = :base

Expand Down
4 changes: 2 additions & 2 deletions spec/support/active_record/initializer.rb
Expand Up @@ -3,5 +3,5 @@

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

require_relative "./schema.rb"
require_relative "./models.rb"
require_relative "./schema"
require_relative "./models"
4 changes: 2 additions & 2 deletions spec/support/sequel/initializer.rb
Expand Up @@ -8,5 +8,5 @@

SEQUEL_DB = Sequel.connect(db)

require_relative "./schema.rb"
require_relative "./models.rb"
require_relative "./schema"
require_relative "./models"

0 comments on commit 6027473

Please sign in to comment.