might 0.7.0 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +19 -0
  3. data/.rubocop.yml +1 -1
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +2 -1
  6. data/Rakefile +1 -0
  7. data/bin/console +1 -0
  8. data/lib/might.rb +45 -0
  9. data/lib/might/fetcher.rb +5 -19
  10. data/lib/might/fetcher_error.rb +1 -0
  11. data/lib/might/filter_middleware.rb +1 -4
  12. data/lib/might/filter_parameter.rb +1 -3
  13. data/lib/might/filter_parameter_definition.rb +1 -4
  14. data/lib/might/filter_parameters.rb +13 -3
  15. data/lib/might/filter_parameters_extractor.rb +1 -5
  16. data/lib/might/filter_parameters_validator.rb +1 -0
  17. data/lib/might/filter_predicates.rb +27 -26
  18. data/lib/might/filter_undefined_parameter.rb +1 -2
  19. data/lib/might/filter_value_validator.rb +2 -10
  20. data/lib/might/pagination_middleware.rb +1 -3
  21. data/lib/might/pagination_parameters_validator.rb +1 -10
  22. data/lib/might/paginator.rb +1 -2
  23. data/lib/might/railtie.rb +1 -1
  24. data/lib/might/ransackable_filter.rb +1 -0
  25. data/lib/might/ransackable_filter_parameters_adapter.rb +1 -0
  26. data/lib/might/ransackable_sort.rb +1 -0
  27. data/lib/might/ransackable_sort_parameters_adapter.rb +1 -0
  28. data/lib/might/result.rb +1 -0
  29. data/lib/might/sort_middleware.rb +1 -5
  30. data/lib/might/sort_parameter.rb +1 -2
  31. data/lib/might/sort_parameter_definition.rb +4 -5
  32. data/lib/might/sort_parameters_extractor.rb +1 -3
  33. data/lib/might/sort_parameters_validator.rb +1 -0
  34. data/lib/might/sort_undefined_parameter.rb +1 -2
  35. data/lib/might/sort_value_validator.rb +2 -10
  36. data/lib/might/version.rb +2 -2
  37. data/might.gemspec +3 -1
  38. metadata +22 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a99e1e236e472a2f44627590833f038129a24b8b
4
- data.tar.gz: 4d73b4d2dc3a555a946a3335baa5eb125b1efe13
2
+ SHA256:
3
+ metadata.gz: f869b4b6ee90b6e24eb8cc2536525a038cff9d26d921a9f9f94c93d24a971249
4
+ data.tar.gz: 2fbed37817a64752e22bb725d365408c7e8355d111a4ee60954cecbe9e237a43
5
5
  SHA512:
6
- metadata.gz: 9725439777f374fe441cee6b05bdfd69fd836fb18a8776141eab222c99c28c128658de13e83aaa174cc8f5d6c9b1284b0bfe433818ded81c47d974f9ad63513f
7
- data.tar.gz: 86ff8d294343e2917804b38c1551a364245d6eba9784eed5e63f52863dc9c8a60e30e8254281da17d52c34bac6da6e83094ec3c25d7c47ab1c37b34c98053541
6
+ metadata.gz: 3f8b92843b3c52236ac5052c38105cdeeb0045d5b007a11958f985511a8d6abd5434c2755bfbd709ac912e9aa55fc3d0097e9d8d3806af89ddc3e27e01b45c94
7
+ data.tar.gz: 4d62a98391fbeb6ac6d04ab0a158847f9b988f6a39c50b5236bcf59dc0a53e705991fac0a91198ea9e738d7bebd429acdd2de7df633f0aa0a92874b4c440b4c2
@@ -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/**/*
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.1
2
+ TargetRubyVersion: 2.3
3
3
  inherit_gem:
4
4
  spbtv_code_style: .rubocop.yml
5
5
 
@@ -1,3 +1,7 @@
1
+ **0.7.2**
2
+
3
+ * Use `autoload` instead of explicit `require` and `require_relative`.
4
+
1
5
  **0.7.0**
2
6
 
3
7
  * Allow to pass block to `FilterParameter#fetch` to customize not found behaviour.
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in might.gemspec
4
5
  gemspec
5
6
 
6
- gem 'codeclimate-test-reporter', group: :test, require: nil
7
+ gem 'codeclimate-test-reporter', '1.0.4', group: :test, require: nil
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bundler/gem_tasks'
2
3
  require 'rspec/core/rake_task'
3
4
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'might'
@@ -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
@@ -1,19 +1,4 @@
1
- require 'might/filter_parameters'
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
- alter_middleware(:use, &block)
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Might
2
3
  class FetcherError < StandardError
3
4
  end
@@ -1,7 +1,4 @@
1
- require_relative 'ransackable_filter'
2
- require_relative 'ransackable_filter_parameters_adapter'
3
- require 'middleware'
4
- #
1
+ # frozen_string_literal: true
5
2
  module Might
6
3
  # Filter scope using ransack gem
7
4
  #
@@ -1,6 +1,4 @@
1
- require 'active_support/core_ext/module/delegation'
2
- require 'active_support/core_ext/object/blank'
3
-
1
+ # frozen_string_literal: true
4
2
  module Might
5
3
  # User provided filtering on particular parameter
6
4
  #
@@ -1,7 +1,4 @@
1
- require 'active_support/core_ext/module/delegation'
2
- require_relative 'filter_predicates'
3
- require_relative 'filter_value_validator'
4
-
1
+ # frozen_string_literal: true
5
2
  module Might
6
3
  # Filtering parameter definition
7
4
  #
@@ -1,6 +1,4 @@
1
- require 'set'
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
- require_relative 'filter_predicates'
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
  # Validates filters and raises error if one of them is invalid
3
4
  #
@@ -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'.freeze
10
- EQ = 'eq'.freeze
11
- DOES_NOT_MATCH = 'does_not_match'.freeze
12
- MATCHES = 'matches'.freeze
13
- GT = 'gt'.freeze
14
- LT = 'lt'.freeze
15
- GTEQ = 'gteq'.freeze
16
- LTEQ = 'lteq'.freeze
17
- NOT_CONT = 'not_cont'.freeze
18
- CONT = 'cont'.freeze
19
- NOT_START = 'not_start'.freeze
20
- START = 'start'.freeze
21
- DOES_NOT_END = 'not_end'.freeze
22
- ENDS = 'end'.freeze
23
- NOT_TRUE = 'not_true'.freeze
24
- TRUE = 'true'.freeze
25
- NOT_FALSE = 'not_false'.freeze
26
- FALSE = 'false'.freeze
27
- BLANK = 'blank'.freeze
28
- PRESENT = 'present'.freeze
29
- NOT_NULL = 'not_null'.freeze
30
- NULL = 'null'.freeze
31
- NOT_IN = 'not_in'.freeze
32
- IN = 'in'.freeze
33
- NOT_CONT_ANY = 'not_cont_any'.freeze
34
- CONT_ANY = 'cont_any'.freeze
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,5 +1,4 @@
1
- require_relative 'filter_parameter_definition'
2
-
1
+ # frozen_string_literal: true
3
2
  module Might
4
3
  # Null object for ParameterDefinition
5
4
  #
@@ -1,12 +1,4 @@
1
- require 'active_support'
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, :'might/filter_value_validator/defined' => true)
25
+ validates(definition.as, 'might/filter_value_validator/defined': true)
34
26
 
35
27
  define_method(:undefined?) { definition.undefined? }
36
28
 
@@ -1,6 +1,4 @@
1
- # require_relative 'validator'
2
- require 'might/paginator'
3
-
1
+ # frozen_string_literal: true
4
2
  module Might
5
3
  # Pagination middleware
6
4
  #
@@ -1,13 +1,4 @@
1
- require 'active_support/concern'
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
@@ -1,5 +1,4 @@
1
- # require 'active_support/core_ext/hash/keys'
2
-
1
+ # frozen_string_literal: true
3
2
  module Might
4
3
  # Paginates ActiveRecord scopes
5
4
  # @example
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/railtie'
2
3
 
3
- #
4
4
  module Might
5
5
  # Load railtie to get translations
6
6
  class Railtie < Rails::Railtie
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Might
2
3
  #
3
4
  class RansackableFilter
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Might
2
3
  # Converts array of parameters to hash familiar to ransack gem
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Might
2
3
  # Sort scope
3
4
  class RansackableSort
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Might
2
3
  # Converts array of parameters to hash familiar to ransack gem
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Might
2
3
  # Marker module
3
4
  module Result
@@ -1,8 +1,4 @@
1
- require 'might/ransackable_sort_parameters_adapter'
2
- require 'might/ransackable_sort'
3
- require 'might/sort_parameters_extractor'
4
- require 'middleware'
5
-
1
+ # frozen_string_literal: true
6
2
  module Might
7
3
  # Sort scope using ransack gem
8
4
  #
@@ -1,5 +1,4 @@
1
- require 'active_support/core_ext/module/delegation'
2
-
1
+ # frozen_string_literal: true
3
2
  module Might
4
3
  # User provided filtering on particular parameter
5
4
  #
@@ -1,5 +1,4 @@
1
- require_relative 'sort_value_validator'
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: :name
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.name == name
30
+ other.is_a?(self.class) && other.as == as
32
31
  end
33
32
 
34
33
  def ==(other)
@@ -1,6 +1,4 @@
1
- require 'might/sort_undefined_parameter'
2
- require 'might/sort_parameter'
3
-
1
+ # frozen_string_literal: true
4
2
  module Might
5
3
  # User provided sorting syntax:
6
4
  # * `name` - sort by name
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Might
2
3
  # Validates sortings and raises error if one of them is invalid
3
4
  #
@@ -1,5 +1,4 @@
1
- require 'might/sort_parameter_definition'
2
-
1
+ # frozen_string_literal: true
3
2
  module Might
4
3
  # Null object for ParameterDefinition
5
4
  #
@@ -1,12 +1,4 @@
1
- require 'active_support'
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, :'might/sort_value_validator/defined' => true)
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) {}
@@ -1,4 +1,4 @@
1
- #
1
+ # frozen_string_literal: true
2
2
  module Might
3
- VERSION = '0.7.0'.freeze
3
+ VERSION = '0.7.5'
4
4
  end
@@ -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', '~> 1.12.5'
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.0
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: 2016-08-18 00:00:00.000000000 Z
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: 1.12.5
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: 1.12.5
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.5.1
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: