[rubocop] fix offences

This commit is contained in:
Nikita Shilnikov 2022-01-16 11:13:12 +03:00
parent 6f7ef07d6e
commit f32f141635
No known key found for this signature in database
GPG Key ID: E569D1D64C40E241
32 changed files with 101 additions and 38 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
source "https://rubygems.org"
eval_gemfile "Gemfile.devtools"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
guard :rspec, cmd: "bundle exec rspec" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^spec/(spec_helper|support)}) { "spec" }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "bundler/setup"
Bundler::GemHelper.install_tasks

View File

@ -1 +1,3 @@
# frozen_string_literal: true
require_relative "dry/initializer"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "set"
# Namespace for gems in a dry-rb community

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
# @private

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
module Builders

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
module Builders
@ -41,15 +43,11 @@ module Dry
end
def params_lines
@definitions.reject(&:option)
.flat_map { |item| Attribute[item] }
.map { |line| " " << line }
@definitions.reject(&:option).flat_map { Attribute[_1] }.map { " #{_1}" }
end
def options_lines
@definitions.select(&:option)
.flat_map { |item| Attribute[item] }
.map { |line| " " << line }
@definitions.select(&:option).flat_map { Attribute[_1] }.map { " #{_1}" }
end
def end_line

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
module Builders

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
module Builders

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
#
@ -23,10 +25,10 @@ module Dry
# @return [Module] reference to the module to be included into class
def mixin
@mixin ||= Module.new.tap do |mod|
__dry_initializer__ = self
initializer = self
mod.extend(Mixin::Local)
mod.send :define_method, :__dry_initializer_config__ do
__dry_initializer__
mod.define_method(:__dry_initializer_config__) do
initializer
end
mod.send :private, :__dry_initializer_config__
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
#
@ -21,11 +23,11 @@ module Dry
default: default,
reader: reader,
desc: desc
}.reject { |_, value| value.nil? }
}.compact
end
def name
@name ||= (option ? "option" : "parameter") << " '#{source}'"
@name ||= "#{option ? "option" : "parameter"} '#{source}'"
end
alias_method :to_s, :name
alias_method :to_str, :name

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# The module is responsible for __normalizing__ arguments
# of `.param` and `.option`.
#

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Prepare nested data type from a block
#
# @example
@ -56,8 +57,15 @@ module Dry
end
def build_struct(klass_name, block)
eval "class #{klass_name} < Dry::Initializer::Struct; end"
const_get(klass_name).tap { |klass| klass.class_eval(&block) }
# rubocop: disable Security/Eval
# rubocop: disable Style/DocumentDynamicEvalDefinition
eval <<~RUBY, TOPLEVEL_BINDING, __FILE__, __LINE__ + 1
class #{klass_name} < Dry::Initializer::Struct
end
RUBY
# rubocop: enable Style/DocumentDynamicEvalDefinition
# rubocop: enable Security/Eval
const_get(klass_name).tap { _1.class_eval(&block) }
end
end
end

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Checks whether an unwrapped type is valid
#
module Dry

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Prepares the `:default` option
#
# It must respond to `.call` without arguments

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Prepares the variable name of a parameter or an option.
#
module Dry

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Defines whether an argument is optional
#
module Dry

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Checks the reader privacy
#
module Dry
@ -9,11 +10,11 @@ module Dry
def call(target: nil, reader: :public, **options)
reader = case reader.to_s
when "false", "" then nil
when "true" then :public
when "public", "private", "protected" then reader.to_sym
else invalid_reader!(target, reader)
end
when "false", "" then nil
when "true" then :public
when "public", "private", "protected" then reader.to_sym
else invalid_reader!(target, reader)
end
{target: target, reader: reader, **options}
end

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# The dispatcher verifies a correctness of the source name
# of param or option, taken as a `:source` option.
#

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Prepares the target name of a parameter or an option.
#
# Unlike source, the target must satisfy requirements for Ruby variable names.

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Looks at the `:type` option and counts how many nested arrays
# it contains around either nil or a callable value.
#
@ -12,15 +13,19 @@ module Dry
extend self
def call(type: nil, wrap: 0, **options)
type, wrap = unwrap(type, 0)
type, count = unwrap(type, wrap)
{type: type, wrap: wrap, **options}
{type: type, wrap: count, **options}
end
private
def unwrap(type, count)
type.is_a?(Array) ? unwrap(type.first, count + 1) : [type, count]
if type.is_a?(::Array)
unwrap(type.first, count + 1)
else
[type, count]
end
end
end
end

View File

@ -1,4 +1,5 @@
#
# frozen_string_literal: true
# Takes `:type` and `:wrap` to construct the final value coercer
#
module Dry

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
# Module-level DSL
@ -37,8 +39,12 @@ module Dry
klass.include Mixin::Root
end
def self.extended(mod)
mod.instance_variable_set :@null, UNDEFINED
class << self
private
def extended(mod)
mod.instance_variable_set :@null, UNDEFINED
end
end
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
# @private

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
module Mixin

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
module Mixin

View File

@ -1,9 +1,10 @@
#
# frozen_string_literal: true
# The nested structure that takes nested hashes with indifferent access
#
class Dry
module Dry
module Initializer
module Struct
class Struct
extend ::Dry::Initializer
class << self

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Dry
module Initializer
module UNDEFINED

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true
module Dry
module Initializer
VERSION = "3.1.0".freeze
VERSION = "3.1.0"
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :benchmark do
desc "Runs benchmarks for plain params"
task :plain_params do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# rubocop: disable Lint/ConstantDefinitionInBlock
namespace :profile do
def profile(name, execution, &definition)