might 0.7.0 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +19 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -1
- data/Rakefile +1 -0
- data/bin/console +1 -0
- data/lib/might.rb +45 -0
- data/lib/might/fetcher.rb +5 -19
- data/lib/might/fetcher_error.rb +1 -0
- data/lib/might/filter_middleware.rb +1 -4
- data/lib/might/filter_parameter.rb +1 -3
- data/lib/might/filter_parameter_definition.rb +1 -4
- data/lib/might/filter_parameters.rb +13 -3
- data/lib/might/filter_parameters_extractor.rb +1 -5
- data/lib/might/filter_parameters_validator.rb +1 -0
- data/lib/might/filter_predicates.rb +27 -26
- data/lib/might/filter_undefined_parameter.rb +1 -2
- data/lib/might/filter_value_validator.rb +2 -10
- data/lib/might/pagination_middleware.rb +1 -3
- data/lib/might/pagination_parameters_validator.rb +1 -10
- data/lib/might/paginator.rb +1 -2
- data/lib/might/railtie.rb +1 -1
- data/lib/might/ransackable_filter.rb +1 -0
- data/lib/might/ransackable_filter_parameters_adapter.rb +1 -0
- data/lib/might/ransackable_sort.rb +1 -0
- data/lib/might/ransackable_sort_parameters_adapter.rb +1 -0
- data/lib/might/result.rb +1 -0
- data/lib/might/sort_middleware.rb +1 -5
- data/lib/might/sort_parameter.rb +1 -2
- data/lib/might/sort_parameter_definition.rb +4 -5
- data/lib/might/sort_parameters_extractor.rb +1 -3
- data/lib/might/sort_parameters_validator.rb +1 -0
- data/lib/might/sort_undefined_parameter.rb +1 -2
- data/lib/might/sort_value_validator.rb +2 -10
- data/lib/might/version.rb +2 -2
- data/might.gemspec +3 -1
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f869b4b6ee90b6e24eb8cc2536525a038cff9d26d921a9f9f94c93d24a971249
|
4
|
+
data.tar.gz: 2fbed37817a64752e22bb725d365408c7e8355d111a4ee60954cecbe9e237a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f8b92843b3c52236ac5052c38105cdeeb0045d5b007a11958f985511a8d6abd5434c2755bfbd709ac912e9aa55fc3d0097e9d8d3806af89ddc3e27e01b45c94
|
7
|
+
data.tar.gz: 4d62a98391fbeb6ac6d04ab0a158847f9b988f6a39c50b5236bcf59dc0a53e705991fac0a91198ea9e738d7bebd429acdd2de7df633f0aa0a92874b4c440b4c2
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
duplication:
|
4
|
+
enabled: true
|
5
|
+
config:
|
6
|
+
languages:
|
7
|
+
- ruby
|
8
|
+
fixme:
|
9
|
+
enabled: true
|
10
|
+
rubocop:
|
11
|
+
enabled: true
|
12
|
+
ratings:
|
13
|
+
paths:
|
14
|
+
- "**.rb"
|
15
|
+
exclude_paths:
|
16
|
+
- bin/**/*
|
17
|
+
- config/**/*
|
18
|
+
- gemfiles/**/*
|
19
|
+
- spec/**/*
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/lib/might.rb
CHANGED
@@ -1,4 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'set'
|
3
|
+
require 'forwardable'
|
4
|
+
require 'active_model'
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/dependencies/autoload'
|
7
|
+
require 'active_support/core_ext/module/delegation'
|
8
|
+
require 'active_support/core_ext/object/blank'
|
9
|
+
require 'active_support/concern'
|
10
|
+
require 'active_support/callbacks'
|
11
|
+
require 'middleware'
|
12
|
+
require 'uber/inheritable_attr'
|
13
|
+
|
1
14
|
# Top level namespace for mighty fetchers
|
2
15
|
module Might
|
3
16
|
require 'might/version'
|
17
|
+
extend ActiveSupport::Autoload
|
18
|
+
|
19
|
+
autoload :Fetcher
|
20
|
+
autoload :FetcherError
|
21
|
+
autoload :FilterMiddleware
|
22
|
+
autoload :FilterParameter
|
23
|
+
autoload :FilterParameterDefinition
|
24
|
+
autoload :FilterParameters
|
25
|
+
autoload :FilterParametersExtractor
|
26
|
+
autoload :FilterParametersValidator
|
27
|
+
autoload :FilterPredicates
|
28
|
+
autoload :FilterUndefinedParameter
|
29
|
+
autoload :FilterValueValidator
|
30
|
+
autoload :PaginationMiddleware
|
31
|
+
autoload :PaginationParametersValidator
|
32
|
+
autoload :Paginator
|
33
|
+
autoload :RansackableFilter
|
34
|
+
autoload :RansackableFilterParametersAdapter
|
35
|
+
autoload :RansackableSort
|
36
|
+
autoload :RansackableSortParametersAdapter
|
37
|
+
autoload :Result
|
38
|
+
autoload :Failure, 'might/result'
|
39
|
+
autoload :Success, 'might/result'
|
40
|
+
autoload :SortMiddleware
|
41
|
+
autoload :SortParameter
|
42
|
+
autoload :FilterUndefinedParameter
|
43
|
+
autoload :SortParameterDefinition
|
44
|
+
autoload :SortParametersExtractor
|
45
|
+
autoload :SortParametersValidator
|
46
|
+
autoload :SortUndefinedParameter
|
47
|
+
autoload :SortValueValidator
|
48
|
+
autoload :VERSION
|
4
49
|
end
|
data/lib/might/fetcher.rb
CHANGED
@@ -1,19 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'might/sort_parameters_extractor'
|
3
|
-
require 'might/sort_parameters_validator'
|
4
|
-
require 'might/filter_parameters_extractor'
|
5
|
-
require 'might/filter_parameters_validator'
|
6
|
-
require 'might/pagination_parameters_validator'
|
7
|
-
|
8
|
-
require 'might/filter_middleware'
|
9
|
-
require 'might/sort_middleware'
|
10
|
-
require 'might/pagination_middleware'
|
11
|
-
|
12
|
-
require 'might/result'
|
13
|
-
require 'uber/inheritable_attr'
|
14
|
-
require 'middleware'
|
15
|
-
|
16
|
-
#
|
1
|
+
# frozen_string_literal: true
|
17
2
|
module Might
|
18
3
|
# Configure your own fetcher
|
19
4
|
#
|
@@ -68,7 +53,7 @@ module Might
|
|
68
53
|
|
69
54
|
# @param params [Hash]
|
70
55
|
def initialize(params)
|
71
|
-
@params = params
|
56
|
+
@params = params.with_indifferent_access
|
72
57
|
end
|
73
58
|
|
74
59
|
# @return [Might::Result] filtered and sorted collection
|
@@ -227,8 +212,9 @@ module Might
|
|
227
212
|
# end
|
228
213
|
# end
|
229
214
|
#
|
230
|
-
def after(&block)
|
231
|
-
|
215
|
+
def after(middleware_or_index = nil, &block)
|
216
|
+
args = middleware_or_index ? [:insert_after, middleware_or_index] : [:use]
|
217
|
+
alter_middleware(*args, &block)
|
232
218
|
end
|
233
219
|
|
234
220
|
# Add middleware to the beginning of middleware chane
|
data/lib/might/fetcher_error.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'forwardable'
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
4
2
|
module Might
|
5
3
|
#
|
6
4
|
class FilterParameters
|
@@ -17,6 +15,18 @@ module Might
|
|
17
15
|
@parameters = Set.new(parameters)
|
18
16
|
end
|
19
17
|
|
18
|
+
# Dup internal set.
|
19
|
+
def initialize_dup(orig)
|
20
|
+
super
|
21
|
+
@parameters = orig.parameters.dup
|
22
|
+
end
|
23
|
+
|
24
|
+
# Clone internal set.
|
25
|
+
def initialize_clone(orig)
|
26
|
+
super
|
27
|
+
@parameters = orig.parameters.clone
|
28
|
+
end
|
29
|
+
|
20
30
|
# Find filter by name
|
21
31
|
# @param name [String]
|
22
32
|
# @return [Might::FilterParameter, nil]
|
@@ -1,8 +1,4 @@
|
|
1
|
-
|
2
|
-
require_relative 'filter_undefined_parameter'
|
3
|
-
require_relative 'filter_parameter'
|
4
|
-
require_relative 'filter_parameters'
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
6
2
|
module Might
|
7
3
|
# User provided filters syntax:
|
8
4
|
# * `{ 'name_eq' => 'Martin' }` - name is equal to Martin
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Might
|
2
3
|
# Contains contains with all supported predicates
|
3
4
|
# You can register your own predicates. Predicates should perform on array or on singular value:
|
@@ -6,32 +7,32 @@ module Might
|
|
6
7
|
# Might::FilterPredicates.register('is_upper_case', on: :value)
|
7
8
|
#
|
8
9
|
module FilterPredicates
|
9
|
-
NOT_EQ = 'not_eq'
|
10
|
-
EQ = 'eq'
|
11
|
-
DOES_NOT_MATCH = 'does_not_match'
|
12
|
-
MATCHES = 'matches'
|
13
|
-
GT = 'gt'
|
14
|
-
LT = 'lt'
|
15
|
-
GTEQ = 'gteq'
|
16
|
-
LTEQ = 'lteq'
|
17
|
-
NOT_CONT = 'not_cont'
|
18
|
-
CONT = 'cont'
|
19
|
-
NOT_START = 'not_start'
|
20
|
-
START = 'start'
|
21
|
-
DOES_NOT_END = 'not_end'
|
22
|
-
ENDS = 'end'
|
23
|
-
NOT_TRUE = 'not_true'
|
24
|
-
TRUE = 'true'
|
25
|
-
NOT_FALSE = 'not_false'
|
26
|
-
FALSE = 'false'
|
27
|
-
BLANK = 'blank'
|
28
|
-
PRESENT = 'present'
|
29
|
-
NOT_NULL = 'not_null'
|
30
|
-
NULL = 'null'
|
31
|
-
NOT_IN = 'not_in'
|
32
|
-
IN = 'in'
|
33
|
-
NOT_CONT_ANY = 'not_cont_any'
|
34
|
-
CONT_ANY = 'cont_any'
|
10
|
+
NOT_EQ = 'not_eq'
|
11
|
+
EQ = 'eq'
|
12
|
+
DOES_NOT_MATCH = 'does_not_match'
|
13
|
+
MATCHES = 'matches'
|
14
|
+
GT = 'gt'
|
15
|
+
LT = 'lt'
|
16
|
+
GTEQ = 'gteq'
|
17
|
+
LTEQ = 'lteq'
|
18
|
+
NOT_CONT = 'not_cont'
|
19
|
+
CONT = 'cont'
|
20
|
+
NOT_START = 'not_start'
|
21
|
+
START = 'start'
|
22
|
+
DOES_NOT_END = 'not_end'
|
23
|
+
ENDS = 'end'
|
24
|
+
NOT_TRUE = 'not_true'
|
25
|
+
TRUE = 'true'
|
26
|
+
NOT_FALSE = 'not_false'
|
27
|
+
FALSE = 'false'
|
28
|
+
BLANK = 'blank'
|
29
|
+
PRESENT = 'present'
|
30
|
+
NOT_NULL = 'not_null'
|
31
|
+
NULL = 'null'
|
32
|
+
NOT_IN = 'not_in'
|
33
|
+
IN = 'in'
|
34
|
+
NOT_CONT_ANY = 'not_cont_any'
|
35
|
+
CONT_ANY = 'cont_any'
|
35
36
|
|
36
37
|
@predicates_on_value = Set.new([
|
37
38
|
NOT_EQ, EQ,
|
@@ -1,12 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/module/delegation'
|
3
|
-
require 'active_model/validator'
|
4
|
-
require 'active_model/validations'
|
5
|
-
require 'active_model/naming'
|
6
|
-
require 'active_model/callbacks'
|
7
|
-
require 'active_model/translation'
|
8
|
-
require 'active_model/errors'
|
9
|
-
|
1
|
+
# frozen_string_literal: true
|
10
2
|
module Might
|
11
3
|
# Build singleton validation class for specified attribute name
|
12
4
|
# @example you need a nice validator for a first_name
|
@@ -30,7 +22,7 @@ module Might
|
|
30
22
|
include ActiveModel::Validations
|
31
23
|
|
32
24
|
validates(definition.as, definition.validations) if definition.validations.present?
|
33
|
-
validates(definition.as,
|
25
|
+
validates(definition.as, 'might/filter_value_validator/defined': true)
|
34
26
|
|
35
27
|
define_method(:undefined?) { definition.undefined? }
|
36
28
|
|
@@ -1,13 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/module/delegation'
|
3
|
-
require 'active_support/callbacks'
|
4
|
-
require 'active_model/naming'
|
5
|
-
require 'active_model/validator'
|
6
|
-
require 'active_model/callbacks'
|
7
|
-
require 'active_model/translation'
|
8
|
-
require 'active_model/errors'
|
9
|
-
require 'active_model/validations'
|
10
|
-
|
1
|
+
# frozen_string_literal: true
|
11
2
|
module Might
|
12
3
|
#
|
13
4
|
class PaginationParametersValidator
|
data/lib/might/paginator.rb
CHANGED
data/lib/might/railtie.rb
CHANGED
data/lib/might/result.rb
CHANGED
data/lib/might/sort_parameter.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
3
2
|
module Might
|
4
3
|
# Sorting parameter definition
|
5
4
|
#
|
@@ -24,11 +23,11 @@ module Might
|
|
24
23
|
@reverse_direction = reverse_direction
|
25
24
|
end
|
26
25
|
|
27
|
-
# If two parameters have the same name, they are equal.
|
28
|
-
delegate :hash, to: :
|
26
|
+
# If two parameters have the same outer name, they are equal.
|
27
|
+
delegate :hash, to: :as
|
29
28
|
|
30
29
|
def eql?(other)
|
31
|
-
other.is_a?(self.class) && other.
|
30
|
+
other.is_a?(self.class) && other.as == as
|
32
31
|
end
|
33
32
|
|
34
33
|
def ==(other)
|
@@ -1,12 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/module/delegation'
|
3
|
-
require 'active_model/validator'
|
4
|
-
require 'active_model/validations'
|
5
|
-
require 'active_model/callbacks'
|
6
|
-
require 'active_model/naming'
|
7
|
-
require 'active_model/translation'
|
8
|
-
require 'active_model/errors'
|
9
|
-
|
1
|
+
# frozen_string_literal: true
|
10
2
|
module Might
|
11
3
|
# Build singleton validation class for specified attribute name
|
12
4
|
# @example you need a nice validator for a first_name
|
@@ -29,7 +21,7 @@ module Might
|
|
29
21
|
Class.new do
|
30
22
|
include ActiveModel::Validations
|
31
23
|
|
32
|
-
validates(definition.name,
|
24
|
+
validates(definition.name, 'might/sort_value_validator/defined': true)
|
33
25
|
|
34
26
|
define_method(:undefined?) { definition.undefined? }
|
35
27
|
define_method(definition.name) {}
|
data/lib/might/version.rb
CHANGED
data/might.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'might/version'
|
@@ -26,9 +27,10 @@ Gem::Specification.new do |spec|
|
|
26
27
|
spec.add_runtime_dependency 'ransack', '>= 1.6.6'
|
27
28
|
spec.add_development_dependency 'activerecord', '>= 3.2', '< 6.0.0'
|
28
29
|
spec.add_development_dependency 'sqlite3', '~> 1.3.11'
|
29
|
-
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'bundler'
|
30
31
|
spec.add_development_dependency 'rake', '~> 11.2.2'
|
31
32
|
spec.add_development_dependency 'rspec', '~> 3.5.0'
|
32
33
|
spec.add_development_dependency 'spbtv_code_style', '1.4.1'
|
33
34
|
spec.add_development_dependency 'appraisal', '2.1.0'
|
35
|
+
spec.add_development_dependency 'rubocop', '0.40.0'
|
34
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: might
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tema Bolshakov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -118,16 +118,16 @@ dependencies:
|
|
118
118
|
name: bundler
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- - "
|
121
|
+
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
123
|
+
version: '0'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
|
-
- - "
|
128
|
+
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
130
|
+
version: '0'
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
132
|
name: rake
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +184,20 @@ dependencies:
|
|
184
184
|
- - '='
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: 2.1.0
|
187
|
+
- !ruby/object:Gem::Dependency
|
188
|
+
name: rubocop
|
189
|
+
requirement: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - '='
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: 0.40.0
|
194
|
+
type: :development
|
195
|
+
prerelease: false
|
196
|
+
version_requirements: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - '='
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: 0.40.0
|
187
201
|
description: Mighty resource fetchers build on top of Ransack gem
|
188
202
|
email:
|
189
203
|
- abolshakov@spbtv.com
|
@@ -191,6 +205,7 @@ executables: []
|
|
191
205
|
extensions: []
|
192
206
|
extra_rdoc_files: []
|
193
207
|
files:
|
208
|
+
- ".codeclimate.yml"
|
194
209
|
- ".gitignore"
|
195
210
|
- ".hound.yml"
|
196
211
|
- ".rspec"
|
@@ -259,9 +274,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
274
|
version: '0'
|
260
275
|
requirements: []
|
261
276
|
rubyforge_project:
|
262
|
-
rubygems_version: 2.
|
277
|
+
rubygems_version: 2.7.6
|
263
278
|
signing_key:
|
264
279
|
specification_version: 4
|
265
280
|
summary: Mighty resource fetchers
|
266
281
|
test_files: []
|
267
|
-
has_rdoc:
|