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

Upgrade gem, documentation, linters & ruby versions #11

Merged
merged 2 commits into from
Feb 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [ '2.7', '3.0', '3.1', '3.2', head ]
ruby-version: [ '3.0', '3.1', '3.2', '3.3', 'head' ]

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ inherit_gem:
- config/ruby-3.0.yml

AllCops:
TargetRubyVersion: 3.2
# Last supported version before EOL
# See: https://endoflife.date/ruby
TargetRubyVersion: 3.0
NewCops: enable
Exclude:
- '**/vendor/**/*'
4 changes: 4 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Last supported version before EOL
# See: https://endoflife.date/ruby
ruby_version: 3.0
format: progress
2 changes: 0 additions & 2 deletions README.yml

This file was deleted.

8 changes: 2 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
require "bundler/gem_tasks"
require "appraisal"
require "rspec/core/rake_task"
require "rubocop/rake_task"
require "standard/rake"

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new

desc "Run the full CI"
task :default do
if ENV["APPRAISAL_INITIALIZED"]
RSpec::Core::RakeTask.new(:spec)
Rake::Task["spec"].invoke
else
# FYI: Standard & appraisal requires each a spawn process.
Expand All @@ -26,6 +22,6 @@ task :default do

fail unless system "bundle exec appraisal rspec"
fail unless system "bundle exec rubocop"
fail unless system "bundle exec rake standard"
fail unless system "bundle exec standardrb"
end
end
66 changes: 66 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Caoutsearch [\ˈkawt͡ˈsɝtʃ\\](http://ipa-reader.xyz/?text=ˈkawt͡ˈsɝtʃ)

<span>[![Gem Version](https://badge.fury.io/rb/caoutsearch.svg)](https://rubygems.org/gems/caoutsearch)</span> <span>
[![CI Status](https://github.com/solutions-territoire/caoutsearch/actions/workflows/ci.yml/badge.svg)](https://github.com/solutions-territoire/caoutsearch/actions/workflows/ci.yml)</span> <span>
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)</span> <span>
[![Maintainability](https://api.codeclimate.com/v1/badges/fbe73db3fd8be9a10e12/maintainability)](https://codeclimate.com/github/solutions-territoire/caoutsearch/maintainability)</span> <span>
[![Test Coverage](https://api.codeclimate.com/v1/badges/fbe73db3fd8be9a10e12/test_coverage)](https://codeclimate.com/github/solutions-territoire/caoutsearch/test_coverage)</span>

<span>[![JRuby](https://github.com/solutions-territoire/caoutsearch/actions/workflows/jruby.yml/badge.svg)](https://github.com/solutions-territoire/caoutsearch/actions/workflows/jruby.yml)</span> <span>
[![Truffle Ruby](https://github.com/solutions-territoire/caoutsearch/actions/workflows/truffle_ruby.yml/badge.svg)](https://github.com/solutions-territoire/caoutsearch/actions/workflows/truffle_ruby.yml)</span>

**!! Gem under development before public release !!**

Caoutsearch is a new Elasticsearch integration for Ruby and/or Rails.
It provides a simple but powerful DSL to perform complex indexing and searching, while securely exposing search criteria to a public and chainable API, without overwhelming your models.

Caoutsearch only supports Elasticsearch 8.x right now.
It is used in production in a robust application, updated and maintained for several years at [Solutions & Territoire](https://solutions-territoire.fr).

Caoutsearch was inspired by awesome gems such as [elasticsearch-rails](https://github.com/elastic/elasticsearch-rails) or [search_flip](https://github.com/mrkamel/search_flip).
Depending on your search scenarios, they may better suite your needs.

## Overview

Caoutsearch let you create `Index` and `Search` classes to manipulate your data :

```ruby
class ArticleIndex < Caoutsearch::Index::Base
property :title
property :published_on
property :tags

def tags
records.tags.public.map(&:to_s)
end
end
```

```ruby
class ArticleSearch < Caoutsearch::Search::Base
filter :title, as: :match
filter :published_on, as: :date
filter :tags

has_aggregation :popular_tags, {
filter: { term: { published: true } },
aggs: {
published: {
terms: { field: :tags, size: 10 }
}
}
}
end
```

You can then index your records

```ruby
ArticleIndex.reindex
```

Or search through them:

```ruby
ArticleSearch.search(published_on: [["now-1y", nil]]).aggregate(:popular_tags)
```
2 changes: 2 additions & 0 deletions index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Overview
icon: home
4 changes: 2 additions & 2 deletions lib/caoutsearch/model/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def index_with(index_class)
end

module ClassMethods
def reindex(*properties, **options, &block)
index_engine_class.reindex(all, *properties, **options, &block)
def reindex(...)
index_engine_class.reindex(all, ...)
end

def delete_indexes
Expand Down
12 changes: 6 additions & 6 deletions lib/caoutsearch/search/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ module Callbacks
end

class_methods do
def before_build(*filters, &blk)
set_callback(:build, :before, *filters, &blk)
def before_build(...)
set_callback(:build, :before, ...)
end

def after_build(*filters, &blk)
set_callback(:build, :after, *filters, &blk)
def after_build(...)
set_callback(:build, :after, ...)
end

def around_build(*filters, &blk)
set_callback(:build, :around, *filters, &blk)
def around_build(...)
set_callback(:build, :around, ...)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/caoutsearch/search/dsl/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def inspect

def properties_to_inspect
PROPERTIES_TO_INSPECT.each_with_object({}) do |name, properties|
value = instance_variable_get("@#{name}")
value = instance_variable_get(:"@#{name}")
properties[name] = value.inspect if value.present?
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/caoutsearch/search/inspect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def inspect

def properties_to_inspect
PROPERTIES_TO_INSPECT.each_with_object({}) do |name, properties|
value = instance_variable_get("@#{name}")
value = instance_variable_get(:"@#{name}")
properties[name] = value.inspect if value
end
end
Expand Down
10 changes: 9 additions & 1 deletion retype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ links:
# target: blank

footer:
copyright: "© 2023 [Solutions & Territoire](https://solutions-territoire.fr) - [MIT License](https://github.com/solutions-territoire/caoutsearch/blob/main/LICENSE)"
copyright: "© 2023 [Solutions & Territoire](https://solutions-territoire.fr) - [MIT License](https://github.com/solutions-territoire/caoutsearch/blob/main/LICENSE)"

edit:
base: docs

exclude:
- "README.md"
- "release_instruction.md"
- "retype_instruction.md"
2 changes: 1 addition & 1 deletion spec/caoutsearch/search/batch_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

RSpec.describe Caoutsearch::Search::BatchMethods, active_record: true do
RSpec.describe Caoutsearch::Search::BatchMethods, :active_record do
let(:search_class) { stub_search_class("SampleSearch") }
let(:search) { search_class.new }
let(:records) { Array.new(12) { Sample.create } }
Expand Down
2 changes: 1 addition & 1 deletion spec/caoutsearch/search/records_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

RSpec.describe Caoutsearch::Search::Records, active_record: true do
RSpec.describe Caoutsearch::Search::Records, :active_record do
let!(:search) { search_class.new }
let!(:search_class) { stub_search_class("SampleSearch") }

Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
expect.syntax = :expect
end

config.before :context, active_record: true do
config.before :context, :active_record do
require "database_cleaner/active_record"
require "active_record"

Expand All @@ -47,7 +47,7 @@
DatabaseCleaner.cleaning { example.run }
end

config.after :context, active_record: true do
config.after :context, :active_record do
ActiveRecord::Schema.define do
suppress_messages do
drop_table :samples
Expand Down
Loading