Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Ruby 3 #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ inherit_mode:
- Exclude

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.1
Exclude:
- '**/tmp/**/*'
- '**/script/**/*'
- Rakefile
- 'bin/*'
UseCache: true
SuggestExtensions: false
NewCops: enable

Metrics/LineLength:
Max: 120
IgnoredPatterns: ['\s*\#\s.*$']
AllowedPatterns: ['\s*\#\s.*$']
Exclude:
- 'spec/**/*'

Expand Down Expand Up @@ -71,6 +73,9 @@ Lint/RaiseException:
Lint/StructNewOverride:
Enabled: true

Lint/EmptyClass:
Enabled: false

# TODO: поговорить с Филиппом про attr
Style/AccessorGrouping:
Enabled: false
Expand Down Expand Up @@ -104,3 +109,8 @@ Style/RedundantRegexpEscape:

Style/SlicingWithRange:
Enabled: true

Style/OpenStructUse:
Exclude:
- 'spec/**/*'

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
3.1.2
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
language: ruby
cache: bundler
rvm:
- 2.5.1
- 3.2.1
before_install: gem install bundler -v 1.17.1
69 changes: 36 additions & 33 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GEM
specs:
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.1)
ast (2.4.2)
bugsnag (6.13.1)
concurrent-ruby (~> 1.0)
byebug (11.1.3)
Expand All @@ -22,8 +22,8 @@ GEM
concurrent-ruby (1.1.6)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.4.4)
docile (1.3.2)
diff-lcs (1.5.0)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dry-configurable (0.11.6)
Expand Down Expand Up @@ -86,8 +86,8 @@ GEM
overcommit (0.55.0)
childprocess (>= 0.6.3, < 5)
iniparse (~> 1.4)
parallel (1.19.2)
parser (2.7.1.4)
parallel (1.22.1)
parser (3.1.3.0)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
Expand All @@ -96,40 +96,41 @@ GEM
byebug (~> 11.0)
pry (~> 0.13.0)
public_suffix (4.0.6)
rainbow (3.0.0)
rainbow (3.1.1)
rake (13.0.1)
regexp_parser (1.7.1)
regexp_parser (2.6.1)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.2)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
rubocop (0.87.1)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.39.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 2.7.1.1)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.1.0, < 1.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.23.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.1.0)
parser (>= 2.7.0.1)
ruby-progressbar (1.10.1)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.24.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.4)
safe_yaml (1.0.5)
sentry-ruby (4.2.1)
Expand All @@ -139,15 +140,17 @@ GEM
sentry-ruby-core (4.2.1)
concurrent-ruby
faraday
simplecov (0.18.5)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.2)
timecop (0.9.1)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
timecop (0.9.5)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
unicode-display_width (1.7.0)
unicode-display_width (2.3.0)
webmock (3.7.6)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand All @@ -171,12 +174,12 @@ DEPENDENCIES
rake (~> 13.0)
rest-client (~> 2.1)
rspec (~> 3.0)
rubocop (~> 0.87)
rubocop (~> 1.39)
sentry-ruby (~> 4.2)
simplecov (~> 0.18)
timecop (~> 0.9)
webmock (~> 3.7.0)
yard (~> 0.9)

BUNDLED WITH
2.2.30
2.3.26
4 changes: 2 additions & 2 deletions lib/luna_park/entities/nested.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module LunaPark
module Entities
# add description
class Nested < Attributable
def self.namespace(name, &block) # rubocop:disable Metrics/MethodLength
def self.namespace(name, &) # rubocop:disable Metrics/MethodLength
serializable_attributes(name)
comparable_attributes(name)

namespace_class = Class.new(Nested)
namespace_class.define_singleton_method(:name) { "Namespace:#{name}" }
namespace_class.class_eval(&block)
namespace_class.class_eval(&)

anonym_mixin = Module.new do
attr_reader(name)
Expand Down
6 changes: 3 additions & 3 deletions lib/luna_park/errors/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def message(txt = nil, i18n_key: nil, i18n: nil, &default_message_block)

def inherited(inheritor)
if __default_message_block__
inheritor.message(i18n_key: i18n_key, &__default_message_block__)
inheritor.message(i18n_key:, &__default_message_block__)
elsif i18n_key
inheritor.message(i18n_key: i18n_key)
inheritor.message(i18n_key:)
end

inheritor.default_notify = default_notify
Expand Down Expand Up @@ -232,7 +232,7 @@ def localized_message(locale = nil, show_error:)
return unless self.class.i18n_key
return unless show_error || I18n.exists?(self.class.i18n_key)

I18n.t(self.class.i18n_key, locale: locale, **details)
I18n.t(self.class.i18n_key, locale:, **details)
end

# @return [String] - Default message
Expand Down
2 changes: 1 addition & 1 deletion lib/luna_park/errors/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def initialize(msg = nil, response:, notify: nil, **details)
raise ArgumentError, 'Response should be Http::Response' unless response.is_a? LunaPark::Http::Response

@response = response
super msg, notify: notify, **details
super msg, notify:, **details
end

# Return request which call this is error.
Expand Down
4 changes: 2 additions & 2 deletions lib/luna_park/extensions/data_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def db_primary_key
end

module InstanceMethods
def transaction(&block)
dataset.transaction(&block)
def transaction(&)
dataset.transaction(&)
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/luna_park/extensions/dsl/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def attr?(*args, **options)
# attrs name1, name2, name3, Type, :type_method, **attr_options
#
# @return [Array of Hash(Symbol => Symbol)] Hash of defined methods
def attrs(*args, **options) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
def attrs(*args, **options) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
*names, type, type_meth = if args.all? { |arg| arg.is_a?(Symbol) }
[*args, nil, nil]
elsif args[0..-2].all? { |arg| arg.is_a?(Symbol) }
Expand All @@ -98,7 +98,7 @@ def attrs(*args, **options) # rubocop:disable Metrics/MethodLength, Metrics/Cycl
args
else
raise ArgumentError, 'must be (*names) | ' \
'(*names, type) | (*names, type, type_meth)'
'(*names, type) | (*names, type, type_meth)'
end

names.map { |name| attr name, type, type_meth, **options }
Expand Down
4 changes: 2 additions & 2 deletions lib/luna_park/extensions/dsl/foreign_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ module InstanceMethods
private

def extract_pk_value_from_object__(object, pk_name)
object.respond_to?(:[]) && object[pk_name] ||
object.respond_to?(pk_name) && object.public_send(pk_name) ||
(object.respond_to?(:[]) && object[pk_name]) ||
(object.respond_to?(pk_name) && object.public_send(pk_name)) ||
nil
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/luna_park/extensions/has_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ module ClassMethods
# logic_error = Service::LogicError.new
# logic_error.is_a? LunaPark::Errors::Business # => true
# logic_error.message # => '2'
def business_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block) # rubocop:disable Metrics/ParameterLists
custom_error title, Errors::Business, txt, i18n: i18n || i18n_key, notify: notify, &default_message_block
def business_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block)
custom_error title, Errors::Business, txt, i18n: i18n || i18n_key, notify:, &default_message_block
end

##
Expand All @@ -92,8 +92,8 @@ def business_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &def
# tech_error = Service::TechError.new
# tech_error.is_a? LunaPark::Errors::System # => true
# tech_error.message # => 'Error message'
def system_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block) # rubocop:disable Metrics/ParameterLists
custom_error title, Errors::System, txt, i18n: i18n || i18n_key, notify: notify, &default_message_block
def system_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block)
custom_error title, Errors::System, txt, i18n: i18n || i18n_key, notify:, &default_message_block
end

##
Expand Down
2 changes: 2 additions & 0 deletions lib/luna_park/extensions/injector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def inherited(inheritor)
dependencies.each_pair do |key, block|
inheritor.dependency(key, &block)
end

super
end

##
Expand Down
8 changes: 4 additions & 4 deletions lib/luna_park/extensions/repositories/postgres/read.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module Postgres
module Read
def find!(pk_value, for_update: false)
ds = dataset.where(primary_key => pk_value)
read_one!(ds, for_update: for_update, not_found_meta: pk_value)
read_one!(ds, for_update:, not_found_meta: pk_value)
end

def find(pk_value, for_update: false)
ds = dataset.where(primary_key => pk_value)
read_one(ds, for_update: for_update)
read_one(ds, for_update:)
end

def lock!(pk_value)
Expand All @@ -37,8 +37,8 @@ def last

private

def read_one!(dataset, for_update: false, not_found_meta:)
read_one(dataset, for_update: for_update).tap do |entity|
def read_one!(dataset, not_found_meta:, for_update: false)
read_one(dataset, for_update:).tap do |entity|
raise Errors::NotFound, "#{short_class_name} (#{not_found_meta})" if entity.nil?
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/luna_park/extensions/typed_attr_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Extensions
module TypedAttrAccessor
def typed_attr_accessor(*names, callable, is_array: false)
attr_reader(*names)
typed_attr_writer(*names, callable, is_array: is_array)
typed_attr_writer(*names, callable, is_array:)
end

def typed_attr_writer(*names, callable, is_array: false)
Expand Down
4 changes: 2 additions & 2 deletions lib/luna_park/extensions/validatable/dry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def self.included(base)
base.extend self
end

def validator(klass = nil, &block)
def validator(klass = nil, &)
return super unless block_given?

klass = Class.new(Validators::Dry)
klass.validation_schema(&block)
klass.validation_schema(&)
super(klass)
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/luna_park/forms/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def submit
if valid?
perform!
true
else false
else
false
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/luna_park/forms/single_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def submit
fill!
perform!
true
else false
else
false
end
end

Expand Down
Loading