ii_finder 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +47 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +196 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/rails50.gemfile +6 -0
- data/gemfiles/rails51.gemfile +6 -0
- data/gemfiles/rails52.gemfile +6 -0
- data/gemfiles/rails60.gemfile +5 -0
- data/gemfiles/rails61.gemfile +5 -0
- data/ii_finder.gemspec +27 -0
- data/lib/ii_finder.rb +19 -0
- data/lib/ii_finder/base.rb +64 -0
- data/lib/ii_finder/callbacks.rb +26 -0
- data/lib/ii_finder/config.rb +22 -0
- data/lib/ii_finder/errors.rb +6 -0
- data/lib/ii_finder/lookup.rb +62 -0
- data/lib/ii_finder/parameter.rb +17 -0
- data/lib/ii_finder/parameters.rb +22 -0
- data/lib/ii_finder/scope.rb +15 -0
- data/lib/ii_finder/version.rb +5 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e3ba37c83b4bc3c8015d95bf52544ea29e90928948c0f5926946e8cb0c49bb3
|
4
|
+
data.tar.gz: c785e88d9b5c78e1a1409cedd805a2944d526de46d6b4acb22272c8c97d732a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67e33beb2d96672958062a58301da0ff1cc9bdb8855572c2e41fa41c685e08a7901d52e6c99df97fec2d986b8043cd59726bd1fbaf3d0c5790854d6720fc8c6d
|
7
|
+
data.tar.gz: 6b70c8f8620928ca1997e79f0178aaba61cd04abfedc5d2ff8e24b7296e9c4e0b7cfaa1be9c4bd05a42ee647e7a5d3c0a532a55e09e285fb362876a914c93470
|
@@ -0,0 +1,47 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-18.04
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0]
|
12
|
+
gemfile: ['rails50', 'rails51', 'rails52', 'rails60', 'rails61']
|
13
|
+
exclude:
|
14
|
+
- ruby: 2.3
|
15
|
+
gemfile: rails60
|
16
|
+
- ruby: 2.3
|
17
|
+
gemfile: rails61
|
18
|
+
- ruby: 2.4
|
19
|
+
gemfile: rails60
|
20
|
+
- ruby: 2.4
|
21
|
+
gemfile: rails61
|
22
|
+
- ruby: 3.0
|
23
|
+
gemfile: rails50
|
24
|
+
- ruby: 3.0
|
25
|
+
gemfile: rails51
|
26
|
+
- ruby: 3.0
|
27
|
+
gemfile: rails52
|
28
|
+
|
29
|
+
name: ruby ${{ matrix.ruby }}, ${{ matrix.gemfile }}
|
30
|
+
|
31
|
+
env:
|
32
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
33
|
+
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v2
|
36
|
+
- uses: ruby/setup-ruby@v1
|
37
|
+
with:
|
38
|
+
ruby-version: ${{ matrix.ruby }}
|
39
|
+
bundler-cache: true
|
40
|
+
- name: Prepare test
|
41
|
+
run: |
|
42
|
+
cd spec/dummy
|
43
|
+
BUNDLE_GEMFILE=../../${{ env.BUNDLE_GEMFILE }} RAILS_ENV=test bundle exec rake db:create db:migrate db:seed
|
44
|
+
cd ../..
|
45
|
+
- name: Run test
|
46
|
+
run: |
|
47
|
+
DEBUG=1 bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Yoshikazu Kaneta
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
# IIFinder
|
2
|
+
|
3
|
+
A base finder to support building relations from parameters.
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
* ruby 2.3+
|
8
|
+
* activesupport 5.0+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'ii_finder'
|
16
|
+
```
|
17
|
+
|
18
|
+
Then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Prepare model:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
class User < ActiveRecord::Base
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Prepare finder:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class UsersFinder < IIFinder::Base
|
35
|
+
parameters :name
|
36
|
+
|
37
|
+
def name(value)
|
38
|
+
@relation.where(name: value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Use finder as follows:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
UsersFinder.call(name: 'NAME').to_sql
|
47
|
+
#=> SELECT "users".* FROM "users" WHERE "users"."name" = 'NAME'
|
48
|
+
```
|
49
|
+
|
50
|
+
You can also specify relation as first argument:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
UsersFinder.call(User.where(id: [1, 2, 3]), name: 'NAME').to_sql
|
54
|
+
#=> SELECT "users".* FROM "users" WHERE "users"."id" IN (1, 2, 3) AND "users"."name" = 'NAME'
|
55
|
+
```
|
56
|
+
|
57
|
+
### Finder
|
58
|
+
|
59
|
+
Finder loops keys of `parameters` and call the corresponding method with value of parameter as argument.
|
60
|
+
Finder method will not be called when the value of parameter is blank.
|
61
|
+
If you want to receive such value, set `allow_blank` as follows:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class UsersFinder < IIFinder::Base
|
65
|
+
parameters :name, allow_blank: true
|
66
|
+
|
67
|
+
def name(value)
|
68
|
+
@relation.where(name: value)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
UsersFinder.call(name: '').to_sql
|
73
|
+
#=> SELECT "users".* FROM "users" WHERE "users"."name" = ''
|
74
|
+
```
|
75
|
+
|
76
|
+
Finder has following attributes:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
class UsersFinder < IIFinder::Base
|
80
|
+
parameters :name
|
81
|
+
|
82
|
+
def name(value)
|
83
|
+
puts "relation: #{@relation}"
|
84
|
+
puts "criteria: #{@criteria}"
|
85
|
+
puts "model: #{@model}"
|
86
|
+
puts "table: #{@table}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
UsersFinder.call(name: 'NAME')
|
91
|
+
#=> relation: #<User::ActiveRecord_Relation:
|
92
|
+
# criteria: {:name=>'NAME'}
|
93
|
+
# model: User
|
94
|
+
# table: #<Arel::Table ...>
|
95
|
+
```
|
96
|
+
|
97
|
+
Return value of each finder method is merged into `@relation` if it is a kind of `ActiveRecord::Relation`.
|
98
|
+
In case you want to merge by yourself, set configuration as follows:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
IIFinder.configure do |config|
|
102
|
+
config.merge_relation = false
|
103
|
+
end
|
104
|
+
|
105
|
+
class UsersFinder < IIFinder::Base
|
106
|
+
parameters :name
|
107
|
+
|
108
|
+
def name(value)
|
109
|
+
@relation = @relation.where(name: value)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
UsersFinder.call(name: 'NAME').to_sql
|
114
|
+
#=> SELECT "users".* FROM "users" WHERE "users"."name" = 'NAME'
|
115
|
+
```
|
116
|
+
|
117
|
+
#### Callbacks
|
118
|
+
|
119
|
+
Following callbacks are available.
|
120
|
+
|
121
|
+
* `before_call`
|
122
|
+
* `around_call`
|
123
|
+
* `after_call`
|
124
|
+
|
125
|
+
For example:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
class UsersFinder < IIFinder::Base
|
129
|
+
after_call :default_order
|
130
|
+
|
131
|
+
def default_order
|
132
|
+
@relation = @relation.order(id: :desc)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
UsersFinder.call.to_sql
|
137
|
+
#=> SELECT "users".* FROM "users" ORDER BY "users"."id" DESC
|
138
|
+
```
|
139
|
+
|
140
|
+
Note that finder does not handle the return value of callback.
|
141
|
+
When you want to update `@relation` in the callback,
|
142
|
+
reassign `@relation` or use methods like `where!` or `order!`.
|
143
|
+
|
144
|
+
### Lookup for model
|
145
|
+
|
146
|
+
Finder lookups related model by its class name when the first argument of `call` is not relation.
|
147
|
+
So the name of finder class should be composed of the name of model class.
|
148
|
+
For example:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
class User < ActiveRecord::Base
|
152
|
+
end
|
153
|
+
|
154
|
+
class UsersFinder < IIFinder::Base
|
155
|
+
end
|
156
|
+
|
157
|
+
IIFinder::Base.lookup(UsersFinder)
|
158
|
+
#=> User
|
159
|
+
```
|
160
|
+
|
161
|
+
Note that superclass of finder is also looked up until related model is found.
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
class User < ActiveRecord::Base
|
165
|
+
end
|
166
|
+
|
167
|
+
class UsersFinder < IIFinder::Base
|
168
|
+
end
|
169
|
+
|
170
|
+
class InheritedUsersFinder < UsersFinder
|
171
|
+
end
|
172
|
+
|
173
|
+
IIFinder::Base.lookup(InheritedUsersFinder)
|
174
|
+
#=> User
|
175
|
+
```
|
176
|
+
|
177
|
+
### Scope for model
|
178
|
+
|
179
|
+
In case you want to call finder from model, include `IIFinder::Scope` into model as follows:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
class User < ActiveRecord::Base
|
183
|
+
include IIFinder::Scope
|
184
|
+
end
|
185
|
+
|
186
|
+
User.finder_scope(name: 'NAME').to_sql
|
187
|
+
#=> SELECT "users".* FROM "users" WHERE "users"."name" = 'NAME'
|
188
|
+
```
|
189
|
+
|
190
|
+
## Contributing
|
191
|
+
|
192
|
+
Bug reports and pull requests are welcome at https://github.com/kanety/ii_finder.
|
193
|
+
|
194
|
+
## License
|
195
|
+
|
196
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ii_finder"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start
|
data/bin/setup
ADDED
data/ii_finder.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ii_finder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ii_finder"
|
8
|
+
spec.version = IIFinder::VERSION
|
9
|
+
spec.authors = ["Yoshikazu Kaneta"]
|
10
|
+
spec.email = ["kaneta@sitebridge.co.jp"]
|
11
|
+
spec.summary = %q{A base finder to support building relations from parameters}
|
12
|
+
spec.description = %q{A base finder to support building relations from parameters}
|
13
|
+
spec.homepage = "https://github.com/kanety/ii_finder"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "activesupport", ">= 5.0"
|
21
|
+
|
22
|
+
spec.add_development_dependency "rails", ">= 5.0"
|
23
|
+
spec.add_development_dependency "sqlite3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec-rails"
|
26
|
+
spec.add_development_dependency "simplecov"
|
27
|
+
end
|
data/lib/ii_finder.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
require 'ii_finder/version'
|
4
|
+
require 'ii_finder/config'
|
5
|
+
require 'ii_finder/errors'
|
6
|
+
require 'ii_finder/base'
|
7
|
+
require 'ii_finder/scope'
|
8
|
+
|
9
|
+
module IIFinder
|
10
|
+
class << self
|
11
|
+
def configure
|
12
|
+
yield Config
|
13
|
+
end
|
14
|
+
|
15
|
+
def config
|
16
|
+
Config
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lookup'
|
4
|
+
require_relative 'parameters'
|
5
|
+
require_relative 'callbacks'
|
6
|
+
|
7
|
+
module IIFinder
|
8
|
+
class Base
|
9
|
+
include Parameters
|
10
|
+
include Callbacks
|
11
|
+
include Lookup
|
12
|
+
|
13
|
+
attr_reader :relation, :criteria, :model, :table
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
if args.size == 0 || args.size == 1
|
17
|
+
@model = self.class.lookup
|
18
|
+
raise IIFinder::Error.new("could not find model for #{self.class}") unless @model
|
19
|
+
@relation = @model.all
|
20
|
+
@criteria = args[0] || {}
|
21
|
+
else
|
22
|
+
@relation = args[0]
|
23
|
+
@criteria = args[1]
|
24
|
+
@model = @relation.klass
|
25
|
+
end
|
26
|
+
@table = @model.arel_table
|
27
|
+
end
|
28
|
+
|
29
|
+
def call
|
30
|
+
run_callbacks :call do
|
31
|
+
self.class._parameters.each do |param|
|
32
|
+
value = fetch_criteria(param.name)
|
33
|
+
if value.present? || param.allow_blank?
|
34
|
+
call_method(param.name, value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@relation
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetch_criteria(name)
|
43
|
+
if @criteria.respond_to?(name)
|
44
|
+
@criteria.send(name)
|
45
|
+
elsif @criteria.respond_to?(:fetch)
|
46
|
+
@criteria.fetch(name, nil)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def call_method(name, value)
|
51
|
+
result = send(name, value)
|
52
|
+
|
53
|
+
if Config.merge_relation && result.is_a?(ActiveRecord::Relation)
|
54
|
+
@relation = @relation.merge(result)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class << self
|
59
|
+
def call(*args)
|
60
|
+
new(*args).call
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IIFinder
|
4
|
+
module Callbacks
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
include ActiveSupport::Callbacks
|
7
|
+
|
8
|
+
included do
|
9
|
+
define_callbacks :call
|
10
|
+
end
|
11
|
+
|
12
|
+
class_methods do
|
13
|
+
def before_call(*args, &block)
|
14
|
+
set_callback(:call, :before, *args, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def after_call(*args, &block)
|
18
|
+
set_callback(:call, :after, *args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def around_call(*args, &block)
|
22
|
+
set_callback(:call, :around, *args, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IIFinder
|
4
|
+
class Config
|
5
|
+
class_attribute :data
|
6
|
+
|
7
|
+
self.data = {
|
8
|
+
lookup_cache: true,
|
9
|
+
merge_relation: true
|
10
|
+
}
|
11
|
+
|
12
|
+
data.keys.each do |key|
|
13
|
+
define_singleton_method "#{key}" do
|
14
|
+
data[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
define_singleton_method "#{key}=" do |val|
|
18
|
+
data[key] = val
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IIFinder
|
4
|
+
module Lookup
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
class_attribute :_model
|
9
|
+
end
|
10
|
+
|
11
|
+
class_methods do
|
12
|
+
def model(model)
|
13
|
+
self._model = model
|
14
|
+
end
|
15
|
+
|
16
|
+
def lookup(klass = self)
|
17
|
+
_model || Lookup.call(klass)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
class_attribute :_cache
|
23
|
+
self._cache = {}
|
24
|
+
|
25
|
+
def call(klass)
|
26
|
+
return if terminate?(klass)
|
27
|
+
|
28
|
+
cache(klass) do
|
29
|
+
if klass.name && (resolved = resolve(klass))
|
30
|
+
resolved
|
31
|
+
elsif klass.superclass
|
32
|
+
call(klass.superclass)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def cache(klass)
|
40
|
+
if Config.lookup_cache
|
41
|
+
self._cache[klass] ||= yield
|
42
|
+
else
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def terminate?(klass)
|
48
|
+
klass.name.to_s.in?(['IIFinder::Base', 'ActiveRecord::Base'])
|
49
|
+
end
|
50
|
+
|
51
|
+
def resolve(klass)
|
52
|
+
resolved_name = if klass < IIFinder::Base
|
53
|
+
klass.name.sub(/Finder$/, '').singularize
|
54
|
+
else
|
55
|
+
klass.name.pluralize + 'Finder'
|
56
|
+
end
|
57
|
+
resolved = resolved_name.safe_constantize
|
58
|
+
return resolved if resolved && resolved_name == resolved.name
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IIFinder
|
4
|
+
class Parameter
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :options
|
7
|
+
|
8
|
+
def initialize(name, options = {})
|
9
|
+
@name = name
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def allow_blank?
|
14
|
+
@options[:allow_blank]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'parameter'
|
4
|
+
|
5
|
+
module IIFinder
|
6
|
+
module Parameters
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
class_attribute :_parameters
|
11
|
+
self._parameters = []
|
12
|
+
end
|
13
|
+
|
14
|
+
class_methods do
|
15
|
+
def parameters(*names, **options)
|
16
|
+
names.each do |name|
|
17
|
+
self._parameters = _parameters + [Parameter.new(name, options)]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IIFinder
|
4
|
+
module Scope
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def finder_scope(criteria)
|
9
|
+
finder = IIFinder::Lookup.call(self)
|
10
|
+
raise IIFinder::Error.new("could not find finder for #{self}") unless finder
|
11
|
+
finder.call(criteria)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ii_finder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoshikazu Kaneta
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A base finder to support building relations from parameters
|
98
|
+
email:
|
99
|
+
- kaneta@sitebridge.co.jp
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".github/workflows/ci.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- CHANGELOG.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- gemfiles/rails50.gemfile
|
115
|
+
- gemfiles/rails51.gemfile
|
116
|
+
- gemfiles/rails52.gemfile
|
117
|
+
- gemfiles/rails60.gemfile
|
118
|
+
- gemfiles/rails61.gemfile
|
119
|
+
- ii_finder.gemspec
|
120
|
+
- lib/ii_finder.rb
|
121
|
+
- lib/ii_finder/base.rb
|
122
|
+
- lib/ii_finder/callbacks.rb
|
123
|
+
- lib/ii_finder/config.rb
|
124
|
+
- lib/ii_finder/errors.rb
|
125
|
+
- lib/ii_finder/lookup.rb
|
126
|
+
- lib/ii_finder/parameter.rb
|
127
|
+
- lib/ii_finder/parameters.rb
|
128
|
+
- lib/ii_finder/scope.rb
|
129
|
+
- lib/ii_finder/version.rb
|
130
|
+
homepage: https://github.com/kanety/ii_finder
|
131
|
+
licenses: []
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubygems_version: 3.1.2
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: A base finder to support building relations from parameters
|
152
|
+
test_files: []
|