[rubocop] fix offences
This commit is contained in:
parent
6f7ef07d6e
commit
f32f141635
2
Gemfile
2
Gemfile
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
eval_gemfile "Gemfile.devtools"
|
||||
|
|
|
@ -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" }
|
||||
|
|
2
Rakefile
2
Rakefile
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "bundler/setup"
|
||||
Bundler::GemHelper.install_tasks
|
||||
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative "dry/initializer"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "set"
|
||||
|
||||
# Namespace for gems in a dry-rb community
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
# @private
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
module Builders
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
module Builders
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
module Builders
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#
|
||||
# frozen_string_literal: true
|
||||
|
||||
# The module is responsible for __normalizing__ arguments
|
||||
# of `.param` and `.option`.
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Checks whether an unwrapped type is valid
|
||||
#
|
||||
module Dry
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Prepares the `:default` option
|
||||
#
|
||||
# It must respond to `.call` without arguments
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Prepares the variable name of a parameter or an option.
|
||||
#
|
||||
module Dry
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Defines whether an argument is optional
|
||||
#
|
||||
module Dry
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
#
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Takes `:type` and `:wrap` to construct the final value coercer
|
||||
#
|
||||
module Dry
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
# @private
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
module Mixin
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
module Mixin
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
module UNDEFINED
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dry
|
||||
module Initializer
|
||||
VERSION = "3.1.0".freeze
|
||||
VERSION = "3.1.0"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
namespace :benchmark do
|
||||
desc "Runs benchmarks for plain params"
|
||||
task :plain_params do
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# rubocop: disable Lint/ConstantDefinitionInBlock
|
||||
namespace :profile do
|
||||
def profile(name, execution, &definition)
|
||||
|
|
Loading…
Reference in New Issue