might 0.5.1 → 0.5.2

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
  SHA1:
3
- metadata.gz: ad96c2f9fdfbd6c5dcd9d741d9ca5dc7de704ebb
4
- data.tar.gz: a2f69450d6b65032942bc95236226aba5710f9a1
3
+ metadata.gz: 16724ee40371d468bd5a932a35a100ae39bff05b
4
+ data.tar.gz: 1211d23fcfb3043dc2da35000d0c500da5b5c2bf
5
5
  SHA512:
6
- metadata.gz: 435e9bacc6502d9d718259716584c07f4685e0c07a6b972cbb7e6af1c6008d5f11bdda84fee7513efb10c43fa40aaf214a88175a6b92848a1097c96022d62cdd
7
- data.tar.gz: b18938e5e5f207e76c2112048465d6e7552dc73e861572a7b1589b05ce273c5732910aa9e50a6f113614c6c058f78eec9eca1d0e87fbf6ef06b66e69e90769a0
6
+ metadata.gz: 1f218d738eab33a02c2b62072fe1cb23cce557ccca6752386892877d41c33f96cabcd35b50161d6d6894b12ae8cd950ea7277a4e362b35ddf8a90f1b8e38684a
7
+ data.tar.gz: eae9d9eb274fc4a539db1457e2f990adcedc73c1d4b2c8aa649c5345bb2e266653a17bb7e2cb91baae3b0406f52356e0ded177d44baa069dc793aec3ad0d529e
@@ -1,3 +1,5 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
1
3
  inherit_gem:
2
4
  spbtv_code_style: .rubocop.yml
3
5
 
@@ -1,6 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.1.5
4
5
  - 2.2.2
5
6
  - 2.2.3
6
7
  - ruby-head
@@ -51,7 +51,7 @@ module Might
51
51
  #
52
52
  # sort :position, as: :relevance, reverse_direction: true
53
53
  #
54
- class Fetcher
54
+ class Fetcher # rubocop:disable Metrics/ClassLength
55
55
  extend Uber::InheritableAttr
56
56
 
57
57
  inheritable_attr :resource_class
@@ -71,7 +71,7 @@ module Might
71
71
  @params = params
72
72
  end
73
73
 
74
- # @return [ActiveRecord::Result] filtered and sorted collection
74
+ # @return [Might::Result] filtered and sorted collection
75
75
  # @yieldparam collection [Result] if a block given
76
76
  #
77
77
  # @example
@@ -91,8 +91,7 @@ module Might
91
91
  result = if errors.any?
92
92
  Failure.new(errors)
93
93
  else
94
- processed_collection, = middleware.call([collection, processed_params])
95
- Success.new(processed_collection)
94
+ Success.new(fetch(processed_params))
96
95
  end
97
96
 
98
97
  if block_given?
@@ -104,14 +103,38 @@ module Might
104
103
 
105
104
  private
106
105
 
106
+ # @param parsed_params [Hash]
107
107
  # @return [ActiveRecord::Relation]
108
- def collection
109
- self.class.resource_class.all
108
+ # @api public
109
+ # This method may be overridden to implement integration with library other than Ransack
110
+ #
111
+ def fetch(parsed_params)
112
+ collection, = middleware.call([self.class.resource_class, parsed_params])
113
+ collection
114
+ end
115
+
116
+ # @return [Hash, Array] tuple of parameters and processing errors
117
+ # this errors may be shown to front-end developer
118
+ # @api public
119
+ def process_params(params)
120
+ process_params_middleware.call([params, []])
121
+ end
122
+
123
+ # Library params processing middleware stack
124
+ # @return [Middleware::Builder]
125
+ def process_params_middleware
126
+ Middleware::Builder.new do |b|
127
+ b.use FilterParametersExtractor, self.class.filter_parameters_definition
128
+ b.use FilterParametersValidator
129
+ b.use SortParametersExtractor, self.class.sort_parameters_definition
130
+ b.use SortParametersValidator
131
+ b.use PaginationParametersValidator
132
+ end
110
133
  end
111
134
 
112
135
  # Library middleware stack
113
136
  # @return [Middleware::Builder]
114
- def default_middleware
137
+ def fetch_middleware
115
138
  Middleware::Builder.new do |b|
116
139
  b.use FilterMiddleware
117
140
  b.use SortMiddleware
@@ -122,25 +145,13 @@ module Might
122
145
  # User modified middleware stack
123
146
  # @return [Middleware::Builder]
124
147
  def middleware
125
- default_middleware.tap do |builder|
148
+ fetch_middleware.tap do |builder|
126
149
  self.class.middleware_changes.each do |change|
127
150
  builder.instance_eval(&change)
128
151
  end
129
152
  end
130
153
  end
131
154
 
132
- # @return [Hash, Array] tuple of parameters and processing errors
133
- # this errors may be shown to front-end developer
134
- def process_params(params)
135
- Middleware::Builder.new do |b|
136
- b.use FilterParametersExtractor, self.class.filter_parameters_definition
137
- b.use FilterParametersValidator
138
- b.use SortParametersExtractor, self.class.sort_parameters_definition
139
- b.use SortParametersValidator
140
- b.use PaginationParametersValidator
141
- end.call([params, []])
142
- end
143
-
144
155
  class << self
145
156
  # Alter middleware chain with the given block
146
157
  # @param [Proc] change
@@ -235,12 +246,11 @@ module Might
235
246
 
236
247
  private
237
248
 
238
- def alter_middleware(method_name, *args, &block)
249
+ def alter_middleware(method_name, *args)
239
250
  fail ArgumentError unless block_given?
240
251
  middleware_changes.push lambda { |builder|
241
252
  builder.send method_name, *args, lambda { |env|
242
- scope, params = env
243
- block.call(scope, params).tap do |r|
253
+ yield(*env).tap do |r|
244
254
  if !r.is_a?(Array) || r.size != 2
245
255
  fail 'After block must return tuple of scope and params'
246
256
  end
@@ -71,7 +71,7 @@ module Might
71
71
  end
72
72
 
73
73
  def undefined?
74
- !self.defined?
74
+ !self.defined? # rubocop:disable Style/RedundantSelf
75
75
  end
76
76
 
77
77
  # Proc with defined validations
@@ -2,32 +2,32 @@ module Might
2
2
  # Contains contains with all supported predicates
3
3
  #
4
4
  module FilterPredicates
5
- NOT_EQ = 'not_eq'
6
- EQ = 'eq'
7
- DOES_NOT_MATCH = 'does_not_match'
8
- MATCHES = 'matches'
9
- GT = 'gt'
10
- LT = 'lt'
11
- GTEQ = 'gteq'
12
- LTEQ = 'lteq'
13
- NOT_CONT = 'not_cont'
14
- CONT = 'cont'
15
- NOT_START = 'not_start'
16
- START = 'start'
17
- DOES_NOT_END = 'not_end'
18
- ENDS = 'end'
19
- NOT_TRUE = 'not_true'
20
- TRUE = 'true'
21
- NOT_FALSE = 'not_false'
22
- FALSE = 'false'
23
- BLANK = 'blank'
24
- PRESENT = 'present'
25
- NOT_NULL = 'not_null'
26
- NULL = 'null'
27
- NOT_IN = 'not_in'
28
- IN = 'in'
29
- NOT_CONT_ANY = 'not_cont_any'
30
- CONT_ANY = 'cont_any'
5
+ NOT_EQ = 'not_eq'.freeze
6
+ EQ = 'eq'.freeze
7
+ DOES_NOT_MATCH = 'does_not_match'.freeze
8
+ MATCHES = 'matches'.freeze
9
+ GT = 'gt'.freeze
10
+ LT = 'lt'.freeze
11
+ GTEQ = 'gteq'.freeze
12
+ LTEQ = 'lteq'.freeze
13
+ NOT_CONT = 'not_cont'.freeze
14
+ CONT = 'cont'.freeze
15
+ NOT_START = 'not_start'.freeze
16
+ START = 'start'.freeze
17
+ DOES_NOT_END = 'not_end'.freeze
18
+ ENDS = 'end'.freeze
19
+ NOT_TRUE = 'not_true'.freeze
20
+ TRUE = 'true'.freeze
21
+ NOT_FALSE = 'not_false'.freeze
22
+ FALSE = 'false'.freeze
23
+ BLANK = 'blank'.freeze
24
+ PRESENT = 'present'.freeze
25
+ NOT_NULL = 'not_null'.freeze
26
+ NULL = 'null'.freeze
27
+ NOT_IN = 'not_in'.freeze
28
+ IN = 'in'.freeze
29
+ NOT_CONT_ANY = 'not_cont_any'.freeze
30
+ CONT_ANY = 'cont_any'.freeze
31
31
 
32
32
  ON_VALUE = [
33
33
  NOT_EQ, EQ,
@@ -41,12 +41,12 @@ module Might
41
41
  NOT_FALSE, FALSE,
42
42
  BLANK, PRESENT,
43
43
  NOT_NULL, NULL
44
- ]
44
+ ].freeze
45
45
 
46
46
  ON_ARRAY = [
47
47
  NOT_IN, IN,
48
48
  NOT_CONT_ANY, CONT_ANY
49
- ]
49
+ ].freeze
50
50
 
51
51
  ALL = ON_VALUE + ON_ARRAY
52
52
  end
@@ -30,11 +30,11 @@ module Might
30
30
  include ActiveModel::Validations
31
31
 
32
32
  validates(definition.as, definition.validations) if definition.validations.present?
33
- validates(definition.as, 'might/filter_value_validator/defined': true)
33
+ validates(definition.as, :'might/filter_value_validator/defined' => true)
34
34
 
35
35
  define_method(:undefined?) { definition.undefined? }
36
36
 
37
- def self.model_name
37
+ define_singleton_method :model_name do
38
38
  ActiveModel::Name.new(Might, nil, 'Might')
39
39
  end
40
40
  end
@@ -10,7 +10,7 @@ module Might
10
10
  scope, params = env
11
11
 
12
12
  ransackable_parameters = Array(params[:filter]).reject { |f| f.predicate.nil? }
13
- .each_with_object({}) do |filter, ransackable_filters|
13
+ .each_with_object({}) do |filter, ransackable_filters|
14
14
  ransackable_filters[canonical_name_for(filter)] = filter.value
15
15
  end
16
16
 
@@ -37,7 +37,7 @@ module Might
37
37
  other.as == as
38
38
  end
39
39
 
40
- alias_method :reverse_direction?, :reverse_direction
40
+ alias reverse_direction? reverse_direction
41
41
 
42
42
  def validator
43
43
  SortValueValidator.build(self).new
@@ -48,7 +48,7 @@ module Might
48
48
  end
49
49
 
50
50
  def undefined?
51
- !self.defined?
51
+ !self.defined? # rubocop:disable Style/RedundantSelf
52
52
  end
53
53
  end
54
54
  end
@@ -29,7 +29,7 @@ module Might
29
29
  Class.new do
30
30
  include ActiveModel::Validations
31
31
 
32
- validates(definition.name, 'might/sort_value_validator/defined': true)
32
+ validates(definition.name, :'might/sort_value_validator/defined' => true)
33
33
 
34
34
  define_method(:undefined?) { definition.undefined? }
35
35
  define_method(definition.name) {}
@@ -1,4 +1,4 @@
1
1
  #
2
2
  module Might
3
- VERSION = '0.5.1'
3
+ VERSION = '0.5.2'.freeze
4
4
  end
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'bundler', '~> 1.10'
30
30
  spec.add_development_dependency 'rake', '~> 10.0'
31
31
  spec.add_development_dependency 'rspec', '~> 3.3'
32
- spec.add_development_dependency 'spbtv_code_style'
32
+ spec.add_development_dependency 'spbtv_code_style', '~> 1.2.3'
33
33
  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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tema Bolshakov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-16 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -154,16 +154,16 @@ dependencies:
154
154
  name: spbtv_code_style
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: 1.2.3
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0'
166
+ version: 1.2.3
167
167
  description: Mighty resource fetchers build on top of Ransack gem
168
168
  email:
169
169
  - abolshakov@spbtv.com