tiny_filter 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b25430ea35a61c7a2ce2bc81b38596990385179c11b4b2797c441df5e1813725
4
- data.tar.gz: ec073eef8a8faf00b171e9ba92fa356a76fa3947b76f314cab3e6997855a618c
3
+ metadata.gz: 33ab33afed080553844b220a53dd8f63f88d303b9b06f751de4f1985f11ca745
4
+ data.tar.gz: 1f62c70732e0cc8a529b851babcd5c3f0ef455626db4faf633a28d8ad79624ef
5
5
  SHA512:
6
- metadata.gz: '0905513bd90fe26f0bc2ead908f73688e3dbe69da16d4864f5e7d64a3be6b0aa1e3f159b270498bb7e8f3c1faced5ac9707a318034c433e3bdc2746e7d9742ba'
7
- data.tar.gz: 98498c4a965f6b7262418e7a952a6b164ef6baa08c869503b971a3461486cb0c6580cf62be73aaff98282d0c4ad3a087203751554fcd92b668ca2f63d2d64e11
6
+ metadata.gz: f3bc9efb9ada2976656c97b849adb4df37428218976f6d5bcc31be2907e8e2158fb7270e9ef89cccb4854a98fd2533fa86e7ea3b503fcefc255264ea48c14f69
7
+ data.tar.gz: 685a3e02de2e4a45d72ee394f961e567202860791b5fba770b6c4519246d611e20e760cd742c9bd850bd6abe98c632f5f776113cd71537c83c947e7802efcb7e
data/.rubocop.yml CHANGED
@@ -3,6 +3,7 @@ require:
3
3
  - rubocop-rails
4
4
  - rubocop-rake
5
5
  - rubocop-rspec
6
+ - rubocop-factory_bot
6
7
 
7
8
  inherit_gem:
8
9
  rubocop-shopify: rubocop.yml
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- ## [Unreleased]
1
+ ## [0.3.0] - 2023-11-06
2
+
3
+ - No runtime dependencies!
4
+ - Sequel integration
5
+
6
+ ## [0.2.1] - 2023-10-20
7
+
8
+ - Do not fix max dependencies versions
9
+ - Improved generators
2
10
 
3
11
  ## [0.2.0] - 2022-12-17
4
12
 
data/CODE_OF_CONDUCT.md CHANGED
@@ -39,7 +39,7 @@ This Code of Conduct applies within all community spaces, and also applies when
39
39
 
40
40
  ## Enforcement
41
41
 
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at kirill.usanov.dev@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at kirill@lassoid.ru. All complaints will be reviewed and investigated promptly and fairly.
43
43
 
44
44
  All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
45
 
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # TinyFilter
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/tiny_filter.svg)](https://rubygems.org/gems/tiny_filter)
3
+ [![Gem Version](https://img.shields.io/gem/v/tiny_filter?color=blue&label=version)](https://rubygems.org/gems/tiny_filter)
4
4
  [![Gem downloads count](https://img.shields.io/gem/dt/tiny_filter)](https://rubygems.org/gems/tiny_filter)
5
5
  [![Github Actions CI](https://github.com/lassoid/tiny_filter/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/lassoid/tiny_filter/actions/workflows/ci.yml)
6
6
 
7
7
  TinyFilter is created to provide a simple object-oriented abstraction layer for filtering collections.
8
- It is mainly purposed for ActiveRecord collections, but you can also use it with any enumerable.
8
+ It is mainly purposed for ActiveRecord/Sequel models, but you can also use it with any enumerable.
9
9
 
10
10
  ```ruby
11
11
  Post.where(title: "Wow!").filter_by(from: 2.days.ago, to: 1.day.ago).order(:created_at)
@@ -83,11 +83,12 @@ Thus if the initial scope for filtering is an ActiveRecord collection,
83
83
  it is a bad practice for filter to return not an ActiveRecord collection.
84
84
  Otherwise you can face errors depending on the provided options order.
85
85
 
86
- ## ActiveRecord integration
86
+ ## ORM integration
87
87
 
88
- ### Helper
88
+ ### ActiveRecord
89
89
 
90
- TinyFilter provides a simple concern, that adds just one method `filter_by`, that can be used in ActiveRecord method chaining.
90
+ TinyFilter provides a simple concern, that adds just one method `filter_by`,
91
+ that can be used in ActiveRecord method chaining.
91
92
 
92
93
  Just include `TinyFilter::Concern` in your model and that's all!
93
94
 
@@ -104,12 +105,30 @@ Post.where(title: "something interesting").filter_by(from: 2.days.ago, to: 1.day
104
105
  Post.filter_by(from: 1.year.ago)
105
106
  ```
106
107
 
108
+ ### Sequel
109
+
110
+ The previously mentioned filter concern can also be used in Sequel models.
111
+
112
+ ```ruby
113
+ class Artist < Sequel::Model
114
+ include TinyFilter::Concern
115
+ end
116
+ ```
117
+
118
+ Querying examples:
119
+
120
+ ```ruby
121
+ Artist.where(name: "Kirill").filter_by(from: 2.days.ago, to: 1.day.ago).order(:name).all
122
+ Artist.filter_by(from: 1.year.ago).all
123
+ ```
124
+
107
125
  ### Naming convention
108
126
 
109
127
  By default a filter class and a model are mapped by a _model name_ with a _suffix_ `Filter`.
110
128
  For example, the model `My::Class` by default will use the `My::ClassFilter` as a filter class.
111
129
 
112
- You can customize this behavior by implementing a `filter_class` class method with an appropriate class as a return value.
130
+ You can customize this behavior by implementing a `filter_class` class method
131
+ with an appropriate class as a return value.
113
132
 
114
133
  ```ruby
115
134
  class My::Class < ApplicationRecord
@@ -123,7 +142,7 @@ end
123
142
 
124
143
  ## Using with Plain objects
125
144
 
126
- You can use filters with non-ActiveRecord collections like so:
145
+ You can use filters with Plain Old Ruby collections like so:
127
146
 
128
147
  ```ruby
129
148
  options # filter options, for example: `{ from: 2.days.ago, to: 1.day.ago }`
@@ -134,11 +153,12 @@ MyFilter.filter(collection, options)
134
153
 
135
154
  ## Development
136
155
 
137
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec`/`rspec` to run the tests.
138
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
156
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests.
157
+ You can also run `bin/rubocop` to lint the source code
158
+ and `bin/console` for an interactive prompt that will allow you to experiment.
139
159
 
140
- To install this gem onto your local machine, run `bundle exec rake install`.
141
- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
160
+ To install this gem onto your local machine, run `bin/rake install`.
161
+ To release a new version, update the version number in `version.rb`, and then run `bin/rake release`,
142
162
  which will create a git tag for the version, push git commits and the created tag,
143
163
  and push the `.gem` file to [rubygems.org](https://rubygems.org).
144
164
 
data/Rakefile CHANGED
@@ -1,12 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rails/generators"
4
+
3
5
  module TinyFilter
4
6
  module Generators
5
7
  class FilterGenerator < ::Rails::Generators::NamedBase
@@ -1,5 +1,5 @@
1
1
  Description:
2
- Generates application filter - base class for all your filters.
2
+ Generates an application filter - a base class for all your filters.
3
3
 
4
4
  Examples:
5
5
  `bin/rails generate tiny_filter:install`
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rails/generators"
4
+
3
5
  module TinyFilter
4
6
  module Generators
5
7
  class InstallGenerator < ::Rails::Generators::Base
@@ -2,13 +2,20 @@
2
2
 
3
3
  module TinyFilter
4
4
  module Concern
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- if defined?(ActiveRecord::Base) && self <= ActiveRecord::Base
9
- scope :filter_by, ->(args = {}) { TinyFilter::FilterFinder.find(self).filter(self, args) }
10
- else
11
- raise Error, "unable to include TinyFilter::Concern in #{self} that is not an ActiveRecord::Base descendant"
5
+ class << self
6
+ def included(other)
7
+ if defined?(ActiveRecord::Base) && other <= ActiveRecord::Base
8
+ other.scope :filter_by, ->(args = {}) { TinyFilter::FilterFinder.find(self).filter(self, args) }
9
+ elsif defined?(Sequel::Model) && other <= Sequel::Model
10
+ other.dataset_module do
11
+ def filter_by(args = {})
12
+ TinyFilter::FilterFinder.find(self).filter(self, args)
13
+ end
14
+ end
15
+ else
16
+ raise Error, "unable to include TinyFilter::Concern in #{other} " \
17
+ "that is not an ActiveRecord::Base or Sequel::Model descendant"
18
+ end
12
19
  end
13
20
  end
14
21
  end
@@ -15,10 +15,18 @@ module TinyFilter
15
15
  if object.respond_to?(:filter_class)
16
16
  object.filter_class
17
17
  elsif object.respond_to?(:model_name)
18
- "#{object.model_name}#{SUFFIX}".constantize
18
+ Object.const_get("#{object.model_name}#{SUFFIX}")
19
+ elsif object.respond_to?(:model)
20
+ if object.model.respond_to?(:filter_class)
21
+ object.model.filter_class
22
+ else
23
+ Object.const_get("#{object.model}#{SUFFIX}")
24
+ end
19
25
  else
20
- raise Error, "unable to find appropriate filter class for #{object}"
26
+ Object.const_get("#{object}#{SUFFIX}")
21
27
  end
28
+ rescue NameError
29
+ raise Error, "unable to find appropriate filter class for #{object}"
22
30
  end
23
31
  end
24
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TinyFilter
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/tiny_filter.gemspec CHANGED
@@ -6,10 +6,10 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "tiny_filter"
7
7
  spec.version = TinyFilter::VERSION
8
8
  spec.authors = ["Kirill Usanov", "LassoID"]
9
- spec.email = ["kirill.usanov.dev@gmail.com"]
9
+ spec.email = "kirill@lassoid.ru"
10
10
 
11
- spec.summary = "Tiny filtering for Rails."
12
- spec.description = "Simple filtering for ActiveRecord and enumerables."
11
+ spec.summary = "Tiny filtering for ActiveRecord, Sequel and enumerables."
12
+ spec.description = "Simple filtering for ActiveRecord, Sequel and enumerables."
13
13
  spec.homepage = "https://github.com/lassoid/tiny_filter"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
@@ -30,9 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  # Dependencies
33
- spec.add_dependency "activesupport", ">= 6.0", "< 7.1"
34
- spec.add_development_dependency "activerecord", ">= 6.0", "< 7.1"
35
- spec.add_development_dependency "railties", ">= 6.0", "< 7.1"
33
+ spec.add_development_dependency "activerecord", ">= 6.0"
34
+ spec.add_development_dependency "railties", ">= 6.0"
36
35
  spec.add_development_dependency "rake"
37
36
  spec.add_development_dependency "rspec"
38
37
  spec.add_development_dependency "rubocop"
@@ -41,5 +40,6 @@ Gem::Specification.new do |spec|
41
40
  spec.add_development_dependency "rubocop-rake"
42
41
  spec.add_development_dependency "rubocop-rspec"
43
42
  spec.add_development_dependency "rubocop-shopify"
43
+ spec.add_development_dependency "sequel"
44
44
  spec.add_development_dependency "sqlite3"
45
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Usanov
@@ -9,28 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-12-17 00:00:00.000000000 Z
12
+ date: 2023-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: activesupport
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '6.0'
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: '7.1'
24
- type: :runtime
25
- prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: '6.0'
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '7.1'
34
14
  - !ruby/object:Gem::Dependency
35
15
  name: activerecord
36
16
  requirement: !ruby/object:Gem::Requirement
@@ -38,9 +18,6 @@ dependencies:
38
18
  - - ">="
39
19
  - !ruby/object:Gem::Version
40
20
  version: '6.0'
41
- - - "<"
42
- - !ruby/object:Gem::Version
43
- version: '7.1'
44
21
  type: :development
45
22
  prerelease: false
46
23
  version_requirements: !ruby/object:Gem::Requirement
@@ -48,9 +25,6 @@ dependencies:
48
25
  - - ">="
49
26
  - !ruby/object:Gem::Version
50
27
  version: '6.0'
51
- - - "<"
52
- - !ruby/object:Gem::Version
53
- version: '7.1'
54
28
  - !ruby/object:Gem::Dependency
55
29
  name: railties
56
30
  requirement: !ruby/object:Gem::Requirement
@@ -58,9 +32,6 @@ dependencies:
58
32
  - - ">="
59
33
  - !ruby/object:Gem::Version
60
34
  version: '6.0'
61
- - - "<"
62
- - !ruby/object:Gem::Version
63
- version: '7.1'
64
35
  type: :development
65
36
  prerelease: false
66
37
  version_requirements: !ruby/object:Gem::Requirement
@@ -68,9 +39,6 @@ dependencies:
68
39
  - - ">="
69
40
  - !ruby/object:Gem::Version
70
41
  version: '6.0'
71
- - - "<"
72
- - !ruby/object:Gem::Version
73
- version: '7.1'
74
42
  - !ruby/object:Gem::Dependency
75
43
  name: rake
76
44
  requirement: !ruby/object:Gem::Requirement
@@ -183,6 +151,20 @@ dependencies:
183
151
  - - ">="
184
152
  - !ruby/object:Gem::Version
185
153
  version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: sequel
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
186
168
  - !ruby/object:Gem::Dependency
187
169
  name: sqlite3
188
170
  requirement: !ruby/object:Gem::Requirement
@@ -197,9 +179,8 @@ dependencies:
197
179
  - - ">="
198
180
  - !ruby/object:Gem::Version
199
181
  version: '0'
200
- description: Simple filtering for ActiveRecord and enumerables.
201
- email:
202
- - kirill.usanov.dev@gmail.com
182
+ description: Simple filtering for ActiveRecord, Sequel and enumerables.
183
+ email: kirill@lassoid.ru
203
184
  executables: []
204
185
  extensions: []
205
186
  extra_rdoc_files: []
@@ -247,8 +228,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
228
  - !ruby/object:Gem::Version
248
229
  version: '0'
249
230
  requirements: []
250
- rubygems_version: 3.3.26
231
+ rubygems_version: 3.4.17
251
232
  signing_key:
252
233
  specification_version: 4
253
- summary: Tiny filtering for Rails.
234
+ summary: Tiny filtering for ActiveRecord, Sequel and enumerables.
254
235
  test_files: []