rubocop -a --only Style/StringLiterals
This commit is contained in:
parent
f5eac5ae36
commit
acbab799c3
20
Gemfile
20
Gemfile
|
@ -1,27 +1,27 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
source 'https://rubygems.org'
|
source "https://rubygems.org"
|
||||||
|
|
||||||
eval_gemfile 'Gemfile.devtools'
|
eval_gemfile "Gemfile.devtools"
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
gem 'dry-logic', github: 'dry-rb/dry-logic', branch: 'master' if ENV['DRY_LOGIC_FROM_MASTER'].eql?('true')
|
gem "dry-logic", github: "dry-rb/dry-logic", branch: "master" if ENV["DRY_LOGIC_FROM_MASTER"].eql?("true")
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'dry-struct'
|
gem "dry-struct"
|
||||||
end
|
end
|
||||||
|
|
||||||
group :tools do
|
group :tools do
|
||||||
gem 'pry-byebug', platform: :mri
|
gem "pry-byebug", platform: :mri
|
||||||
end
|
end
|
||||||
|
|
||||||
group :benchmarks do
|
group :benchmarks do
|
||||||
platform :mri do
|
platform :mri do
|
||||||
gem 'attrio'
|
gem "attrio"
|
||||||
gem 'benchmark-ips'
|
gem "benchmark-ips"
|
||||||
gem 'fast_attributes'
|
gem "fast_attributes"
|
||||||
gem 'hotch'
|
gem "hotch"
|
||||||
gem 'virtus'
|
gem "virtus"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
14
Rakefile
14
Rakefile
|
@ -1,22 +1,22 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'bundler/gem_tasks'
|
require "bundler/gem_tasks"
|
||||||
require 'rspec/core/rake_task'
|
require "rspec/core/rake_task"
|
||||||
|
|
||||||
task :run_specs do
|
task :run_specs do
|
||||||
require 'rspec/core'
|
require "rspec/core"
|
||||||
|
|
||||||
types_result = RSpec::Core::Runner.run(['spec/dry'])
|
types_result = RSpec::Core::Runner.run(["spec/dry"])
|
||||||
RSpec.clear_examples
|
RSpec.clear_examples
|
||||||
|
|
||||||
Dry::Types.load_extensions(:maybe)
|
Dry::Types.load_extensions(:maybe)
|
||||||
ext_result = RSpec::Core::Runner.run(['spec'])
|
ext_result = RSpec::Core::Runner.run(["spec"])
|
||||||
|
|
||||||
exit [types_result, ext_result].max
|
exit [types_result, ext_result].max
|
||||||
end
|
end
|
||||||
|
|
||||||
task default: :run_specs
|
task default: :run_specs
|
||||||
|
|
||||||
require 'yard'
|
require "yard"
|
||||||
require 'yard/rake/yardoc_task'
|
require "yard/rake/yardoc_task"
|
||||||
YARD::Rake::YardocTask.new(:doc)
|
YARD::Rake::YardocTask.new(:doc)
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
$LOAD_PATH.unshift('lib')
|
$LOAD_PATH.unshift("lib")
|
||||||
|
|
||||||
require 'bundler/setup'
|
require "bundler/setup"
|
||||||
require 'dry-types'
|
require "dry-types"
|
||||||
|
|
||||||
module SchemaBench
|
module SchemaBench
|
||||||
def self.hash_schema(type)
|
def self.hash_schema(type)
|
||||||
Dry::Types['nominal.hash'].public_send(
|
Dry::Types["nominal.hash"].public_send(
|
||||||
type,
|
type,
|
||||||
email: Dry::Types['nominal.string'],
|
email: Dry::Types["nominal.string"],
|
||||||
age: Dry::Types['params.integer'],
|
age: Dry::Types["params.integer"],
|
||||||
admin: Dry::Types['params.bool'],
|
admin: Dry::Types["params.bool"],
|
||||||
address: Dry::Types['nominal.hash'].public_send(
|
address: Dry::Types["nominal.hash"].public_send(
|
||||||
type,
|
type,
|
||||||
city: Dry::Types['nominal.string'],
|
city: Dry::Types["nominal.string"],
|
||||||
street: Dry::Types['nominal.string']
|
street: Dry::Types["nominal.string"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -29,14 +29,14 @@ module SchemaBench
|
||||||
.to_h
|
.to_h
|
||||||
|
|
||||||
INPUT = {
|
INPUT = {
|
||||||
email: 'jane@doe.org',
|
email: "jane@doe.org",
|
||||||
age: '20',
|
age: "20",
|
||||||
admin: '1',
|
admin: "1",
|
||||||
address: { city: 'NYC', street: 'Street 1/2' }
|
address: { city: "NYC", street: "Street 1/2" }
|
||||||
}.freeze
|
}.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'benchmark/ips'
|
require "benchmark/ips"
|
||||||
|
|
||||||
Benchmark.ips do |x|
|
Benchmark.ips do |x|
|
||||||
SchemaBench::SCHEMAS.each do |schema_type, schema|
|
SchemaBench::SCHEMAS.each do |schema_type, schema|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'setup'
|
require_relative "setup"
|
||||||
|
|
||||||
schema = Dry::Types['params.hash'].schema(
|
schema = Dry::Types["params.hash"].schema(
|
||||||
email?: 'string',
|
email?: "string",
|
||||||
age?: 'params.integer'
|
age?: "params.integer"
|
||||||
).lax
|
).lax
|
||||||
|
|
||||||
params = { email: 'jane@doe.org', age: '19' }
|
params = { email: "jane@doe.org", age: "19" }
|
||||||
|
|
||||||
Benchmark.ips do |x|
|
Benchmark.ips do |x|
|
||||||
x.report('valid input') { schema.(params) }
|
x.report("valid input") { schema.(params) }
|
||||||
x.compare!
|
x.compare!
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'setup'
|
require_relative "setup"
|
||||||
|
|
||||||
INVALID_INPUT = {
|
INVALID_INPUT = {
|
||||||
name: :John,
|
name: :John,
|
||||||
age: '20',
|
age: "20",
|
||||||
email: nil
|
email: nil
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'setup'
|
require_relative "setup"
|
||||||
|
|
||||||
Schema = Dry::Types['params.hash'].schema(
|
Schema = Dry::Types["params.hash"].schema(
|
||||||
email?: 'string',
|
email?: "string",
|
||||||
age?: 'coercible.integer'
|
age?: "coercible.integer"
|
||||||
).lax
|
).lax
|
||||||
|
|
||||||
ValidInput = { email: 'jane@doe.org', age: '19' }.freeze
|
ValidInput = { email: "jane@doe.org", age: "19" }.freeze
|
||||||
|
|
||||||
profile do
|
profile do
|
||||||
10_000.times do
|
10_000.times do
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'setup'
|
require_relative "setup"
|
||||||
|
|
||||||
VALID_INPUT = {
|
VALID_INPUT = {
|
||||||
name: 'John',
|
name: "John",
|
||||||
age: 20,
|
age: 20,
|
||||||
email: 'john@doe.com'
|
email: "john@doe.com"
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
profile do
|
profile do
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'setup'
|
require_relative "setup"
|
||||||
|
|
||||||
VALID_INPUT = {
|
VALID_INPUT = {
|
||||||
name: 'John',
|
name: "John",
|
||||||
age: 20,
|
age: 20,
|
||||||
email: 'john@doe.com'
|
email: "john@doe.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
INVALID_INPUT = {
|
INVALID_INPUT = {
|
||||||
name: :John,
|
name: :John,
|
||||||
age: '20',
|
age: "20",
|
||||||
email: nil
|
email: nil
|
||||||
}
|
}
|
||||||
|
|
||||||
Benchmark.ips do |x|
|
Benchmark.ips do |x|
|
||||||
x.report('valid input') { PersonSchema.(VALID_INPUT) }
|
x.report("valid input") { PersonSchema.(VALID_INPUT) }
|
||||||
x.report('invalid input') { PersonSchema.(INVALID_INPUT) }
|
x.report("invalid input") { PersonSchema.(INVALID_INPUT) }
|
||||||
x.compare!
|
x.compare!
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'benchmark/ips'
|
require "benchmark/ips"
|
||||||
require 'hotch'
|
require "hotch"
|
||||||
ENV['HOTCH_VIEWER'] ||= 'open'
|
ENV["HOTCH_VIEWER"] ||= "open"
|
||||||
|
|
||||||
require 'dry/types'
|
require "dry/types"
|
||||||
|
|
||||||
PersonSchema = Dry::Types['hash'].schema(
|
PersonSchema = Dry::Types["hash"].schema(
|
||||||
name: 'string',
|
name: "string",
|
||||||
age: 'integer',
|
age: "integer",
|
||||||
email: 'string'
|
email: "string"
|
||||||
).lax
|
).lax
|
||||||
|
|
||||||
def profile(&block)
|
def profile(&block)
|
||||||
Hotch(filter: 'Dry', &block)
|
Hotch(filter: "Dry", &block)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'dry/types'
|
require "dry/types"
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'bigdecimal'
|
require "bigdecimal"
|
||||||
require 'date'
|
require "date"
|
||||||
require 'set'
|
require "set"
|
||||||
|
|
||||||
require 'concurrent/map'
|
require "concurrent/map"
|
||||||
|
|
||||||
require 'dry-container'
|
require "dry-container"
|
||||||
require 'dry-equalizer'
|
require "dry-equalizer"
|
||||||
require 'dry/core/extensions'
|
require "dry/core/extensions"
|
||||||
require 'dry/core/constants'
|
require "dry/core/constants"
|
||||||
require 'dry/core/class_attributes'
|
require "dry/core/class_attributes"
|
||||||
|
|
||||||
require 'dry/types/version'
|
require "dry/types/version"
|
||||||
require 'dry/types/container'
|
require "dry/types/container"
|
||||||
require 'dry/types/inflector'
|
require "dry/types/inflector"
|
||||||
require 'dry/types/type'
|
require "dry/types/type"
|
||||||
require 'dry/types/printable'
|
require "dry/types/printable"
|
||||||
require 'dry/types/nominal'
|
require "dry/types/nominal"
|
||||||
require 'dry/types/constructor'
|
require "dry/types/constructor"
|
||||||
require 'dry/types/module'
|
require "dry/types/module"
|
||||||
|
|
||||||
require 'dry/types/errors'
|
require "dry/types/errors"
|
||||||
|
|
||||||
module Dry
|
module Dry
|
||||||
# Main library namespace
|
# Main library namespace
|
||||||
|
@ -45,7 +45,7 @@ module Dry
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def self.included(*)
|
def self.included(*)
|
||||||
raise 'Import Dry.Types, not Dry::Types'
|
raise "Import Dry.Types, not Dry::Types"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return container with registered built-in type objects
|
# Return container with registered built-in type objects
|
||||||
|
@ -121,7 +121,7 @@ module Dry
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def self.identifier(klass)
|
def self.identifier(klass)
|
||||||
Inflector.underscore(klass).tr('/', '.')
|
Inflector.underscore(klass).tr("/", ".")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Cached type map
|
# Cached type map
|
||||||
|
@ -137,11 +137,11 @@ module Dry
|
||||||
def self.const_missing(const)
|
def self.const_missing(const)
|
||||||
underscored = Inflector.underscore(const)
|
underscored = Inflector.underscore(const)
|
||||||
|
|
||||||
if container.keys.any? { |key| key.split('.')[0] == underscored }
|
if container.keys.any? { |key| key.split(".")[0] == underscored }
|
||||||
raise NameError,
|
raise NameError,
|
||||||
'dry-types does not define constants for default types. '\
|
"dry-types does not define constants for default types. "\
|
||||||
'You can access the predefined types with [], e.g. Dry::Types["integer"] '\
|
'You can access the predefined types with [], e.g. Dry::Types["integer"] '\
|
||||||
'or generate a module with types using Dry.Types()'
|
"or generate a module with types using Dry.Types()"
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
@ -204,6 +204,6 @@ module Dry
|
||||||
# rubocop:enable Naming/MethodName
|
# rubocop:enable Naming/MethodName
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'dry/types/core' # load built-in types
|
require "dry/types/core" # load built-in types
|
||||||
require 'dry/types/extensions'
|
require "dry/types/extensions"
|
||||||
require 'dry/types/printer'
|
require "dry/types/printer"
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'support/coverage'
|
require_relative "support/coverage"
|
||||||
require_relative 'support/warnings'
|
require_relative "support/warnings"
|
||||||
require_relative 'support/rspec_options'
|
require_relative "support/rspec_options"
|
||||||
|
|
||||||
require 'pathname'
|
require "pathname"
|
||||||
|
|
||||||
SPEC_ROOT = Pathname(__FILE__).dirname
|
SPEC_ROOT = Pathname(__FILE__).dirname
|
||||||
|
|
||||||
require 'dry-types'
|
require "dry-types"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'pry-byebug'
|
require "pry-byebug"
|
||||||
rescue LoadError; end
|
rescue LoadError; end
|
||||||
Dir[Pathname(__dir__).join('shared/*.rb')].each(&method(:require))
|
Dir[Pathname(__dir__).join("shared/*.rb")].each(&method(:require))
|
||||||
require 'dry/types/spec/types'
|
require "dry/types/spec/types"
|
||||||
|
|
||||||
Undefined = Dry::Core::Constants::Undefined
|
Undefined = Dry::Core::Constants::Undefined
|
||||||
|
|
||||||
require 'dry/core/deprecations'
|
require "dry/core/deprecations"
|
||||||
Dry::Core::Deprecations.set_logger!(SPEC_ROOT.join('../log/deprecations.log'))
|
Dry::Core::Deprecations.set_logger!(SPEC_ROOT.join("../log/deprecations.log"))
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.before(:example, :maybe) do
|
config.before(:example, :maybe) do
|
||||||
|
@ -30,9 +30,9 @@ RSpec.configure do |config|
|
||||||
@types = Dry::Types.container._container.keys
|
@types = Dry::Types.container._container.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before { stub_const('Test', Module.new) }
|
config.before { stub_const("Test", Module.new) }
|
||||||
|
|
||||||
config.order = 'random'
|
config.order = "random"
|
||||||
end
|
end
|
||||||
|
|
||||||
srand RSpec.configuration.seed
|
srand RSpec.configuration.seed
|
||||||
|
|
Loading…
Reference in New Issue