Skip to content

Commit

Permalink
fix cops
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Aug 28, 2024
1 parent be0e930 commit 845ae15
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AllCops:
- test/dummy/db/schema.rb
- gemfiles/**/*
- bin/**/*
TargetRubyVersion: 3.0
TargetRubyVersion: 3.1

# Department Bundler
Bundler/DuplicatedGem:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.3.4
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gemspec

gem "appraisal", "~> 2.2"
gem "bundler", ">= 1.17", "< 3"
gem "appraisal"
gem "bundler"
gem "debug"
gem "faker"
gem "minitest", "~> 5.0"
gem "minitest"
gem "mocha"
gem "rake", "~> 13.0"
gem "rake"
gem "rubocop"
gem "rubocop-minitest"
gem "rubocop-performance"
gem "rubocop-rake"
gem "simplecov"
gem "sqlite3"

gem "activerecord", "~> 7.1"
gem "activerecord"
18 changes: 9 additions & 9 deletions lib/redi_search/aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ def verbatim
end

def load(*fields)
add_to_clauses(Clauses::Load.new(fields: fields))
add_to_clauses(Clauses::Load.new(fields:))
end

def group_by(*fields)
add_to_clauses(Clauses::GroupBy.new(fields: fields))
add_to_clauses(Clauses::GroupBy.new(fields:))
end

def count(as: nil)
clause = clauses.reverse.find { |cl| cl.is_a?(Clauses::GroupBy) } ||
raise(MissingGroupByClause, "call group_by first")

clause.count(as: as)
clause.count(as:)
self
end

def quantile(property: nil, quantile: nil, as: nil)
clause = clauses.reverse.find { |cl| cl.is_a?(Clauses::GroupBy) } ||
raise(MissingGroupByClause, "call group_by first")

clause.count(property: property, quantile: quantile, as: as)
clause.count(property:, quantile:, as:)

self
end
Expand All @@ -56,25 +56,25 @@ def quantile(property: nil, quantile: nil, as: nil)
clause = clauses.reverse.find { |cl| cl.is_a?(Clauses::GroupBy) } ||
raise(MissingGroupByClause, "call group_by first")

clause.public_send(reducer, property: property, as: as)
clause.public_send(reducer, property:, as:)
self
end
end

def sort_by(*fields)
add_to_clauses(Clauses::SortBy.new(fields: fields))
add_to_clauses(Clauses::SortBy.new(fields:))
end

def apply(expression, as:)
add_to_clauses(Clauses::Apply.new(expression: expression, as: as))
add_to_clauses(Clauses::Apply.new(expression:, as:))
end

def filter(expression)
add_to_clauses(Clauses::Filter.new(expression: expression))
add_to_clauses(Clauses::Filter.new(expression:))
end

def limit(total, offset = 0)
add_to_clauses(Clauses::Limit.new(total: total, offset: offset))
add_to_clauses(Clauses::Limit.new(total:, offset:))
end

private
Expand Down
20 changes: 10 additions & 10 deletions lib/redi_search/aggregate/clauses/group_by.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,53 @@ def clause
end

def count(as: nil)
self.reducer = Reducers::Count.new(as: as).tap(&:validate!)
self.reducer = Reducers::Count.new(as:).tap(&:validate!)
end

def distinct_count(property:, as: nil)
self.reducer = Reducers::DistinctCount.
new(property: property, as: as).tap(&:validate!)
new(property:, as:).tap(&:validate!)
end

def distinctish_count(property:, as: nil)
self.reducer = Reducers::DistinctishCount.
new(property: property, as: as).tap(&:validate!)
new(property:, as:).tap(&:validate!)
end

def sum(property:, as: nil)
self.reducer = Reducers::Sum.
new(property: property, as: as).tap(&:validate!)
new(property:, as:).tap(&:validate!)
end

def min(property:, as: nil)
self.reducer = Reducers::Min.
new(property: property, as: as).tap(&:validate!)
new(property:, as:).tap(&:validate!)
end

def max(property:, as: nil)
self.reducer = Reducers::Max.
new(property: property, as: as).tap(&:validate!)
new(property:, as:).tap(&:validate!)
end

def average(property:, as: nil)
self.reducer = Reducers::Average.
new(property: property, as: as).tap(&:validate!)
new(property:, as:).tap(&:validate!)
end

def stdev(property:, as: nil)
self.reducer = Reducers::Stdev.
new(property: property, as: as).tap(&:validate!)
new(property:, as:).tap(&:validate!)
end

def quantile(property:, quantile:, as: nil)
self.reducer = Reducers::Quantile.new(
property: property, quantile: quantile, as: as
property:, quantile:, as:
).tap(&:validate!)
end

def to_list(property:, as: nil)
self.reducer = Reducers::ToList.
new(property: property, as: as).tap(&:validate!)
new(property:, as:).tap(&:validate!)
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/redi_search/application_clause.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def clause_order(number)

def define_validation(term, type, options)
if options.is_a? Hash
public_send("validates_#{type}_of", term, **options)
public_send(:"validates_#{type}_of", term, **options)
else
public_send("validates_#{type}_of", term)
public_send(:"validates_#{type}_of", term)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/redi_search/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def send_command(command, *params)
def instrument(action, payload, &block)
ActiveSupport::Notifications.instrument(
"action.redi_search",
{ name: "RediSearch", action: action, inside_pipeline: pipeline }.
{ name: "RediSearch", action:, inside_pipeline: pipeline }.
merge(payload),
&Proc.new(&(block || proc {}))
&Proc.new(&block || proc {})
)
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/redi_search/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module RediSearch
class Index
attr_reader :name, :schema, :model

def initialize(name, model = nil, &schema)
def initialize(name, model = nil, &)
@name = name.to_s
@schema = Schema.new(&schema)
@schema = Schema.new(&)
@model = model
end

Expand All @@ -19,7 +19,7 @@ def aggregate(term = nil, **term_options)
end

def spellcheck(query, distance: 1)
Spellcheck.new(self, query, distance: distance)
Spellcheck.new(self, query, distance:)
end

def create(**options)
Expand All @@ -31,7 +31,7 @@ def create!(**options)
end

def drop(keep_docs: false)
drop!(keep_docs: keep_docs)
drop!(keep_docs:)
rescue Redis::CommandError
false
end
Expand Down Expand Up @@ -92,8 +92,8 @@ def document_count
end

# rubocop:disable Style/ArgumentsForwarding
def add_field(name, type, **options, &block)
AddField.new(self, name, type, **options, &block).call!
def add_field(name, type, **options, &)
AddField.new(self, name, type, **options, &).call!
end
# rubocop:enable Style/ArgumentsForwarding

Expand Down
14 changes: 7 additions & 7 deletions lib/redi_search/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module ClassMethods
attr_reader :search_index

# rubocop:disable Metrics/MethodLength
def redi_search(**options, &schema)
def redi_search(**options, &)
@search_index = Index.new(
[options[:index_prefix], model_name.plural, RediSearch.env].
compact.join("_"),
self, &schema
self, &
)
register_search_commit_hooks

Expand Down Expand Up @@ -44,22 +44,22 @@ def aggregate(term = nil, **term_options)
end

def spellcheck(term, distance: 1)
search_index.spellcheck(term, distance: distance)
search_index.spellcheck(term, distance:)
end

def reindex(recreate: false, only: [], batch_size: 1000)
search_import.find_in_batches(batch_size: batch_size).all? do |group|
search_import.find_in_batches(batch_size:).all? do |group|
search_index.reindex(
group.map { |record| record.search_document(only: only) },
recreate: recreate
group.map { |record| record.search_document(only:) },
recreate:
)
end
end
end

module InstanceMethods
def search_document(only: [])
Document.for_object(self.class.search_index, self, only: only)
Document.for_object(self.class.search_index, self, only:)
end

def remove_from_index
Expand Down
4 changes: 2 additions & 2 deletions lib/redi_search/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module RediSearch
class Schema
attr_reader :fields

def initialize(&block)
def initialize(&)
@fields = []

instance_exec(&block)
instance_exec(&)
end

def text_field(name, ...)
Expand Down
6 changes: 3 additions & 3 deletions lib/redi_search/schema/text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def initialize(name, weight: 1.0, phonetic: nil, sortable: false,
@name = name
@value_block = block

{ weight: weight, phonetic: phonetic, sortable: sortable,
no_index: no_index, no_stem: no_stem }.each do |attr, value|
instance_variable_set("@#{attr}", value)
{ weight:, phonetic:, sortable:,
no_index:, no_stem: }.each do |attr, value|
instance_variable_set(:"@#{attr}", value)
end
end

Expand Down
14 changes: 7 additions & 7 deletions lib/redi_search/search/clauses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ def with_sort_keys
end

def return(*fields)
add_to_clauses(Return.new(fields: fields))
add_to_clauses(Return.new(fields:))
end

def highlight(fields: [], opening_tag: "<b>", closing_tag: "</b>")
add_to_clauses(Highlight.new(
fields: fields, opening_tag: opening_tag, closing_tag: closing_tag
fields:, opening_tag:, closing_tag:
))
end

def slop(slop)
add_to_clauses(Slop.new(slop: slop))
add_to_clauses(Slop.new(slop:))
end

def timeout(timeout)
add_to_clauses(Timeout.new(timeout: timeout))
add_to_clauses(Timeout.new(timeout:))
end

def in_order
add_to_clauses(InOrder.new)
end

def language(language)
add_to_clauses(Language.new(language: language))
add_to_clauses(Language.new(language:))
end

def sort_by(field, order: :asc)
add_to_clauses(SortBy.new(field: field, order: order))
add_to_clauses(SortBy.new(field:, order:))
end

def limit(total, offset = 0)
add_to_clauses(Limit.new(total: total, offset: offset))
add_to_clauses(Limit.new(total:, offset:))
end

def count
Expand Down
6 changes: 3 additions & 3 deletions lib/redi_search/validatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ module ClassMethods
def validates_inclusion_of(field, within:, **options)
self.validations = [
*validations.to_a,
Validations::Inclusion.new(field: field, within: within, **options)
Validations::Inclusion.new(field:, within:, **options)
]
end

def validates_presence_of(field)
self.validations = [
*validations.to_a,
Validations::Presence.new(field: field)
Validations::Presence.new(field:)
]
end

def validates_numericality_of(field, within:, **options)
self.validations = [
*validations.to_a,
Validations::Numericality.new(
field: field, within: within, **options
field:, within:, **options
)
]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/redi_search/validations/numericality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def validate_numberness!(value)
end

def validate_inclusion!(object)
Inclusion.new(field: field, within: within).validate!(object)
Inclusion.new(field:, within:).validate!(object)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions redi_search.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
"changelog_uri" => "https://github.com/npezza93/redi_search/releases",
}

spec.required_ruby_version = ">= 3.0"
spec.required_ruby_version = ">= 3.1"

spec.add_runtime_dependency "activesupport", ">= 5.1", "< 8.0"
spec.add_runtime_dependency "redis", ">= 4.0", "< 6.0"
spec.add_runtime_dependency "zeitwerk"
spec.add_dependency "activesupport", "< 9.0"
spec.add_dependency "redis", ">= 4.0"
spec.add_dependency "zeitwerk"
end
2 changes: 1 addition & 1 deletion test/unit/redi_search/log_subscriber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_explaincli

def instrument(action, payload)
@log_subscriber.action(Event.new(
0.9, name: "RediSearch", action: action, **payload
0.9, name: "RediSearch", action:, **payload
))
end
end
Expand Down
Loading

0 comments on commit 845ae15

Please sign in to comment.