Skip to content

Commit

Permalink
Remove ruby 2.x (#911)
Browse files Browse the repository at this point in the history
* Remove ruby 2.x

* Fix rubocop
  • Loading branch information
Danil Nurgaliev authored Dec 13, 2023
1 parent 6addcb3 commit f9681e4
Show file tree
Hide file tree
Showing 44 changed files with 125 additions and 163 deletions.
30 changes: 2 additions & 28 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,13 @@ on:
]

jobs:
ruby-2:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: [2.6, 2.7]
gemfile: [rails.5.2.activerecord, rails.6.0.activerecord, rails.6.1.activerecord]
name: ${{ matrix.ruby }}-${{ matrix.gemfile }}

env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@9de0f78f306e4ebc0838f057e6b754364685e759
with:
stack-version: 7.10.1
port: 9250
- name: Tests
run: bundle exec rspec

ruby-3:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: [ '3.0', '3.1', '3.2' ]
gemfile: [ rails.6.1.activerecord, rails.7.0.activerecord, rails.7.1.activerecord ]
gemfile: [rails.6.1.activerecord, rails.7.0.activerecord, rails.7.1.activerecord]
name: ${{ matrix.ruby }}-${{ matrix.gemfile }}

env:
Expand All @@ -69,6 +43,6 @@ jobs:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.0
bundler-cache: true
- run: bundle exec rubocop --format simple
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
TargetRubyVersion: 2.6
TargetRubyVersion: 3.0

Layout/AccessModifierIndentation:
EnforcedStyle: outdent
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### New Features

* [#890](https://github.com/toptal/chewy/pull/890): Add the [`knn`](https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html) option to the request. ([@jkostolansky][])
* [#911](https://github.com/toptal/chewy/pull/911): Remove ruby 2.x. ([@konalegi][])

### Changes

Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
source 'https://rubygems.org'

gemspec

gem 'activerecord'

gem 'activejob', require: false
Expand All @@ -18,5 +16,7 @@ gem 'guard-rspec'
gem 'redcarpet'
gem 'yard'

gem 'rexml' if RUBY_VERSION >= '3.0.0'
gem 'ruby2_keywords' if RUBY_VERSION < '2.7'
gem 'rexml'

eval_gemfile 'gemfiles/base.gemfile'
gemspec
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Or install it yourself as:

### Ruby

Chewy is compatible with MRI 2.6-3.0¹.
Chewy is compatible with MRI 3.0-3.2¹.

> ¹ Ruby 3 is only supported with Rails 6.1
Expand Down
20 changes: 3 additions & 17 deletions chewy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'chewy/version'

Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
Gem::Specification.new do |spec|
spec.name = 'chewy'
spec.version = Chewy::VERSION
spec.authors = ['Toptal, LLC', 'pyromaniac']
Expand All @@ -14,24 +14,10 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength

spec.files = `git ls-files`.split($RS)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_development_dependency 'database_cleaner'
spec.add_development_dependency 'elasticsearch-extensions'
spec.add_development_dependency 'mock_redis'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '>= 3.7.0'
spec.add_development_dependency 'rspec-collection_matchers'
spec.add_development_dependency 'rspec-its'
spec.add_development_dependency 'rubocop', '1.11'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'timecop'

spec.add_development_dependency 'method_source'
spec.add_development_dependency 'unparser'

spec.add_dependency 'activesupport', '>= 5.2'
spec.add_dependency 'activesupport', '>= 5.2' # Remove with major version bump, 8.x
spec.add_dependency 'elasticsearch', '>= 7.12.0', '< 7.14.0'
spec.add_dependency 'elasticsearch-dsl'
spec.metadata['rubygems_mfa_required'] = 'true'
end
12 changes: 12 additions & 0 deletions gemfiles/base.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
gem 'database_cleaner'
gem 'elasticsearch-extensions'
gem 'method_source'
gem 'mock_redis'
gem 'rake'
gem 'rspec', '>= 3.7.0'
gem 'rspec-collection_matchers'
gem 'rspec-its'
gem 'rubocop', '1.48'
gem 'sqlite3'
gem 'timecop'
gem 'unparser'
11 changes: 0 additions & 11 deletions gemfiles/rails.5.2.activerecord.gemfile

This file was deleted.

11 changes: 0 additions & 11 deletions gemfiles/rails.6.0.activerecord.gemfile

This file was deleted.

3 changes: 2 additions & 1 deletion gemfiles/rails.6.1.activerecord.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem 'parallel', require: false
gem 'rspec_junit_formatter', '~> 0.4.1'
gem 'sidekiq', require: false

gem 'rexml' if RUBY_VERSION >= '3.0.0'
gem 'rexml'

gemspec path: '../'
eval_gemfile 'base.gemfile'
3 changes: 2 additions & 1 deletion gemfiles/rails.7.0.activerecord.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem 'parallel', require: false
gem 'rspec_junit_formatter', '~> 0.4.1'
gem 'sidekiq', require: false

gem 'rexml' if RUBY_VERSION >= '3.0.0'
gem 'rexml'

gemspec path: '../'
eval_gemfile 'base.gemfile'
3 changes: 2 additions & 1 deletion gemfiles/rails.7.1.activerecord.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem 'parallel', require: false
gem 'rspec_junit_formatter', '~> 0.4.1'
gem 'sidekiq', require: false

gem 'rexml' if RUBY_VERSION >= '3.0.0'
gem 'rexml'

gemspec path: '../'
eval_gemfile 'base.gemfile'
2 changes: 1 addition & 1 deletion lib/chewy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def try_require(path)
require 'chewy/fields/base'
require 'chewy/fields/root'
require 'chewy/journal'
require 'chewy/railtie' if defined?(::Rails::Railtie)
require 'chewy/railtie' if defined?(Rails::Railtie)

ActiveSupport.on_load(:active_record) do
include Chewy::Index::Observe::ActiveRecordMethods
Expand Down
22 changes: 12 additions & 10 deletions lib/chewy/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,19 @@ def configuration
private

def yaml_settings
@yaml_settings ||= begin
if defined?(Rails::VERSION)
file = Rails.root.join('config', 'chewy.yml')
@yaml_settings ||= build_yaml_settings || {}
end

if File.exist?(file)
yaml = ERB.new(File.read(file)).result
hash = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(yaml) : YAML.load(yaml) # rubocop:disable Security/YAMLLoad
hash[Rails.env].try(:deep_symbolize_keys) if hash
end
end || {}
end
def build_yaml_settings
return unless defined?(Rails::VERSION)

file = Rails.root.join('config', 'chewy.yml')

return unless File.exist?(file)

yaml = ERB.new(File.read(file)).result
hash = YAML.unsafe_load(yaml)
hash[Rails.env].try(:deep_symbolize_keys) if hash
end

def build_search_class(base)
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/fields/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def mappings_hash
mappings[name]
end

ruby2_keywords def dynamic_template(*args)
def dynamic_template(*args)
options = args.extract_options!.deep_symbolize_keys
if args.first
template_name = :"template_#{dynamic_templates.count.next}"
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/index/adapter/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Adapter
class ActiveRecord < Orm
def self.accepts?(target)
defined?(::ActiveRecord::Base) && (
target.is_a?(Class) && target < ::ActiveRecord::Base ||
(target.is_a?(Class) && target < ::ActiveRecord::Base) ||
target.is_a?(::ActiveRecord::Relation))
end

Expand Down
6 changes: 3 additions & 3 deletions lib/chewy/index/adapter/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def identify(collection)
# @param args [Array<#to_json>]
# @option options [Integer] :batch_size import processing batch size
# @return [true, false]
ruby2_keywords def import(*args, &block)
def import(*args, &block)
collection, options = import_args(*args)
import_objects(collection, options, &block)
end
Expand Down Expand Up @@ -113,7 +113,7 @@ def identify(collection)
# end
#
# @see Chewy::Index::Adapter::Base#import_fields
ruby2_keywords def import_fields(*args, &block)
def import_fields(*args, &block)
return enum_for(:import_fields, *args) unless block_given?

options = args.extract_options!
Expand All @@ -139,7 +139,7 @@ def identify(collection)
# For the Object adapter returns the objects themselves in batches.
#
# @see Chewy::Index::Adapter::Base#import_references
ruby2_keywords def import_references(*args, &block)
def import_references(*args, &block)
return enum_for(:import_references, *args) unless block_given?

collection, options = import_args(*args)
Expand Down
4 changes: 2 additions & 2 deletions lib/chewy/index/adapter/orm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def identify(collection)
# # or
# UsersIndex.import users.map(&:id) # user ids will be deleted from index
#
ruby2_keywords def import(*args, &block)
def import(*args, &block)
collection, options = import_args(*args)

if !collection.is_a?(relation_class) || options[:direct_import]
Expand All @@ -82,7 +82,7 @@ def identify(collection)
end
end

ruby2_keywords def import_fields(*args, &block)
def import_fields(*args, &block)
return enum_for(:import_fields, *args) unless block_given?

collection, options = import_args(*args)
Expand Down
4 changes: 2 additions & 2 deletions lib/chewy/index/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module ClassMethods
# @option options [true, false] update_failover enables full objects reimport in cases of partial update errors, `true` by default
# @option options [true, Integer, Hash] parallel enables parallel import processing with the Parallel gem, accepts the number of workers or any Parallel gem acceptable options
# @return [true, false] false in case of errors
ruby2_keywords def import(*args)
def import(*args)
intercept_import_using_strategy(*args).blank?
end

Expand All @@ -83,7 +83,7 @@ module ClassMethods
# in case of any import errors.
#
# @raise [Chewy::ImportFailed] in case of errors
ruby2_keywords def import!(*args)
def import!(*args)
errors = intercept_import_using_strategy(*args)

raise Chewy::ImportFailed.new(self, errors) if errors.present?
Expand Down
4 changes: 2 additions & 2 deletions lib/chewy/index/import/bulk_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ def load_cache
.filter(ids: {values: ids_for_cache})
.order('_doc')
.pluck(:_id, :_routing, join_field)
.map do |id, routing, join|
.to_h do |id, routing, join|
[
id,
{routing: routing, parent_id: join['parent']}
]
end.to_h
end
end

def existing_routing(id)
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/index/observe/active_record_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def initialize_chewy_callbacks
end
end

ruby2_keywords def update_index(type_name, *args, &block)
def update_index(type_name, *args, &block)
callback_options = Observe.extract_callback_options!(args)
update_proc = Observe.update_proc(type_name, *args, &block)
callback = Chewy::Index::Observe::Callback.new(update_proc, callback_options)
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/index/syncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Index
# @see Chewy::Index::Actions::ClassMethods#sync
class Syncer
DEFAULT_SYNC_BATCH_SIZE = 20_000
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/.freeze
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
OUTDATED_IDS_WORKER = lambda do |outdated_sync_field_type, source_data_hash, index, total, index_data|
::Process.setproctitle("chewy [#{index}]: sync outdated calculation (#{::Parallel.worker_number + 1}/#{total})") if index
index_data.each_with_object([]) do |(id, index_sync_value), result|
Expand Down
4 changes: 3 additions & 1 deletion lib/chewy/minitest/search_index_receiver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# The class will capture the data from the *param on the Chewy::Index.bulk method and
# aggregate the data for test analysis.
class SearchIndexReceiver
MUTATION_FOR_CLASS = Struct.new(:indexes, :deletes, keyword_init: true)

def initialize
@mutations = {}
end
Expand Down Expand Up @@ -71,6 +73,6 @@ def updated_indexes
# @param index [Chewy::Index] the index to fetch.
# @return [#indexes, #deletes] an object with a list of indexes and a list of deletes.
def mutation_for(index)
@mutations[index] ||= OpenStruct.new(indexes: [], deletes: [])
@mutations[index] ||= MUTATION_FOR_CLASS.new(indexes: [], deletes: [])
end
end
6 changes: 3 additions & 3 deletions lib/chewy/rake_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ def warn_missing_index(output)
return if journal_exists?

output.puts "############################################################\n" \
"WARN: You are risking to lose some changes during the reset.\n" \
" Please consider enabling journaling.\n" \
" See https://github.com/toptal/chewy#journaling\n" \
"WARN: You are risking to lose some changes during the reset.\n " \
"Please consider enabling journaling.\n " \
"See https://github.com/toptal/chewy#journaling\n" \
'############################################################'
end

Expand Down
Loading

0 comments on commit f9681e4

Please sign in to comment.