might 0.6.0 → 0.7.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
  SHA1:
3
- metadata.gz: 15a3ffb400a36a96c6479bd3717c94622b064437
4
- data.tar.gz: fb6e300fedf6060ec38e7d2dab644a9faf8673cb
3
+ metadata.gz: a99e1e236e472a2f44627590833f038129a24b8b
4
+ data.tar.gz: 4d73b4d2dc3a555a946a3335baa5eb125b1efe13
5
5
  SHA512:
6
- metadata.gz: b2325e15a768c3726bb4a7d06ccdc7550999eb769fa9bc0f575828b88f2625826cacba54f76c97c74aadb7176a7628d1cfcf66f9899a6eb0c6019b603b4f8061
7
- data.tar.gz: bcf3c17a88edeb04959dc1818e3951539b65c3bdf06b4fa1d85830bb4e2fe0a760299ab351ec6e9ea5e7300672832d283dcfa2491c5cd60f3a4a4f82803a674a
6
+ metadata.gz: 9725439777f374fe441cee6b05bdfd69fd836fb18a8776141eab222c99c28c128658de13e83aaa174cc8f5d6c9b1284b0bfe433818ded81c47d974f9ad63513f
7
+ data.tar.gz: 86ff8d294343e2917804b38c1551a364245d6eba9784eed5e63f52863dc9c8a60e30e8254281da17d52c34bac6da6e83094ec3c25d7c47ab1c37b34c98053541
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  spec/examples.txt
11
+ gemfiles/*.gemfile.lock
@@ -1,15 +1,13 @@
1
- sudo: false
1
+ ---
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.5
5
- - 2.2.2
6
- - 2.2.3
7
- - ruby-head
8
- matrix:
9
- allow_failures:
10
- - rvm: ruby-head
11
- fast_finish: true
12
- before_install: gem install bundler -v 1.10.6
4
+ - 2.2.5
5
+ - 2.3.1
13
6
  script:
14
- - bundle exec rake spec
15
- - bundle exec rubocop --fail-level C
7
+ - bundle exec rake spec
8
+ - bundle exec rubocop --fail-level C
9
+ gemfile:
10
+ - gemfiles/rails_4.2.7_ransack_1.6.6.gemfile
11
+ - gemfiles/rails_4.2.7_ransack_1.8.2.gemfile
12
+ - gemfiles/rails_5.0.0_ransack_1.6.6.gemfile
13
+ - gemfiles/rails_5.0.0_ransack_1.8.2.gemfile
@@ -0,0 +1,27 @@
1
+ require 'yaml'
2
+
3
+ ruby_versions = %w(2.2.5 2.3.1)
4
+ rails_versions = %w(4.2.7 5.0.0)
5
+ ransack_versions = %w(1.6.6 1.8.2)
6
+
7
+ rails_versions.product(ransack_versions).each do |(rails, ransack)|
8
+ appraise "rails_#{rails}_ransack_#{ransack}" do
9
+ gem 'activerecord', rails
10
+ gem 'activesupport', rails
11
+ gem 'ransack', ransack
12
+ end
13
+ end
14
+
15
+ ::File.open('.travis.yml', 'w+') do |f|
16
+ travis_hash = {
17
+ 'language' => 'ruby',
18
+ 'rvm' => ruby_versions,
19
+ 'script' => [
20
+ 'bundle exec rake spec',
21
+ 'bundle exec rubocop --fail-level C'
22
+ ],
23
+ 'gemfile' => Dir.glob('gemfiles/*.gemfile')
24
+ }
25
+ travis = ::YAML.dump(travis_hash)
26
+ f.write travis
27
+ end
@@ -1,3 +1,13 @@
1
+ **0.7.0**
2
+
3
+ * Allow to pass block to `FilterParameter#fetch` to customize not found behaviour.
4
+ * Implement `FilterParameter#delete`.
5
+ * `FilterParameters` is not derived from `Set` anymore.
6
+
7
+ **0.6.1**
8
+
9
+ * Add error message to `Failure#get`
10
+
1
11
  **0.6.0**
2
12
 
3
13
  * Implement public API for registering predicates
data/README.md CHANGED
@@ -303,6 +303,16 @@ new version, update the version number in `version.rb`, and then run `bundle exe
303
303
  which will create a git tag for the version, push git commits and tags, and push the `.gem`
304
304
  file to [rubygems.org](https://rubygems.org).
305
305
 
306
+
307
+ We test `Might` against different versions of `ActiveRecord` and `Ransack` using [appraisal](https://github.com/thoughtbot/appraisal) gem.
308
+ To regenerate gemfiles run:
309
+
310
+ $ appraisal install
311
+
312
+ To run specs against all versions:
313
+
314
+ $ appraisal rake spec
315
+
306
316
  ## License
307
317
 
308
318
  Copyright 2015 SPB TV AG
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "codeclimate-test-reporter", :group => :test, :require => nil
6
+ gem "activerecord", "4.2.7"
7
+ gem "activesupport", "4.2.7"
8
+ gem "ransack", "1.6.6"
9
+
10
+ gemspec :path => "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "codeclimate-test-reporter", :group => :test, :require => nil
6
+ gem "activerecord", "4.2.7"
7
+ gem "activesupport", "4.2.7"
8
+ gem "ransack", "1.8.2"
9
+
10
+ gemspec :path => "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "codeclimate-test-reporter", :group => :test, :require => nil
6
+ gem "activerecord", "5.0.0"
7
+ gem "activesupport", "5.0.0"
8
+ gem "ransack", "1.6.6"
9
+
10
+ gemspec :path => "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "codeclimate-test-reporter", :group => :test, :require => nil
6
+ gem "activerecord", "5.0.0"
7
+ gem "activesupport", "5.0.0"
8
+ gem "ransack", "1.8.2"
9
+
10
+ gemspec :path => "../"
@@ -71,7 +71,7 @@ module Might
71
71
  end
72
72
 
73
73
  def undefined?
74
- !self.defined? # rubocop:disable Style/RedundantSelf
74
+ !self.defined?
75
75
  end
76
76
 
77
77
  # Proc with defined validations
@@ -1,33 +1,83 @@
1
1
  require 'set'
2
+ require 'forwardable'
2
3
 
3
4
  module Might
4
5
  #
5
- class FilterParameters < Set
6
+ class FilterParameters
7
+ include Comparable
8
+ include Enumerable
9
+ extend Forwardable
10
+
6
11
  FilterError = Class.new(KeyError)
7
12
 
13
+ def_delegators :parameters, :detect, :each
14
+
15
+ # @param [<Might::FilterParameter>]
16
+ def initialize(parameters = nil)
17
+ @parameters = Set.new(parameters)
18
+ end
19
+
8
20
  # Find filter by name
9
21
  # @param name [String]
10
22
  # @return [Might::FilterParameter, nil]
11
23
  #
12
24
  def [](name)
13
- detect { |filter| filter.name == name }
25
+ parameters.detect { |filter| filter.name == name }
14
26
  end
15
27
 
16
28
  # Find filter by name or raise error
17
29
  # @param name [String]
30
+ # @yieldparam name [String]
31
+ # block value will be returned if no `FilterParameter` found with specified name
18
32
  # @return [Might::FilterParameter]
19
33
  # @raise FilterError
20
34
  #
21
35
  def fetch(name)
22
36
  if (filter = self[name])
23
37
  filter
38
+ elsif block_given?
39
+ yield(name)
24
40
  else
25
41
  fail FilterError, "filter not found: #{name.inspect}"
26
42
  end
27
43
  end
28
44
 
45
+ # param value [Might::FilterParameter]
46
+ def add(value)
47
+ self.class.new(parameters.add(value))
48
+ end
49
+
50
+ alias << add
51
+
29
52
  def map(&block)
30
- dup.map!(&block)
53
+ self.class.new(parameters.map(&block))
31
54
  end
55
+
56
+ # param other [Might::FilterParameters]
57
+ def -(other)
58
+ self.class.new(parameters - other.parameters)
59
+ end
60
+
61
+ # param other [Might::FilterParameters]
62
+ def +(other)
63
+ self.class.new(parameters.merge(other.parameters))
64
+ end
65
+
66
+ # Delete filter by name
67
+ # @param name [String]
68
+ # @return [Might::FilterParameter, nil]
69
+ def delete(name)
70
+ filter_parameter = self[name]
71
+ parameters.delete(filter_parameter) if filter_parameter
72
+ filter_parameter
73
+ end
74
+
75
+ def <=>(other)
76
+ parameters <=> other.parameters
77
+ end
78
+
79
+ protected
80
+
81
+ attr_reader :parameters
32
82
  end
33
83
  end
@@ -55,7 +55,7 @@ module Might
55
55
  predicate = FilterPredicates.all.detect { |p| name_with_predicate.end_with?("_#{p}") }
56
56
  [
57
57
  name_with_predicate.chomp("_#{predicate}"),
58
- predicate
58
+ predicate,
59
59
  ]
60
60
  end
61
61
 
@@ -34,22 +34,22 @@ module Might
34
34
  CONT_ANY = 'cont_any'.freeze
35
35
 
36
36
  @predicates_on_value = Set.new([
37
- NOT_EQ, EQ,
38
- DOES_NOT_MATCH, MATCHES,
39
- GT, LT,
40
- GTEQ, LTEQ,
41
- NOT_CONT, CONT,
42
- NOT_START, START,
43
- DOES_NOT_END, ENDS,
44
- NOT_TRUE, TRUE,
45
- NOT_FALSE, FALSE,
46
- BLANK, PRESENT,
47
- NOT_NULL, NULL
48
- ])
37
+ NOT_EQ, EQ,
38
+ DOES_NOT_MATCH, MATCHES,
39
+ GT, LT,
40
+ GTEQ, LTEQ,
41
+ NOT_CONT, CONT,
42
+ NOT_START, START,
43
+ DOES_NOT_END, ENDS,
44
+ NOT_TRUE, TRUE,
45
+ NOT_FALSE, FALSE,
46
+ BLANK, PRESENT,
47
+ NOT_NULL, NULL
48
+ ])
49
49
  @predicates_on_array = Set.new([
50
- NOT_IN, IN,
51
- NOT_CONT_ANY, CONT_ANY
52
- ])
50
+ NOT_IN, IN,
51
+ NOT_CONT_ANY, CONT_ANY
52
+ ])
53
53
 
54
54
  # Registers predicate on singular value or on array
55
55
  # @param predicate [String, Symbol]
@@ -49,7 +49,7 @@ module Might
49
49
  def default_pagination_options
50
50
  {
51
51
  limit: @per_page,
52
- offset: 0
52
+ offset: 0,
53
53
  }.with_indifferent_access
54
54
  end
55
55
  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
 
@@ -52,8 +52,8 @@ module Might
52
52
  polymorphic_name = filter.on.keys.first
53
53
 
54
54
  name = Array(filter.on.values.first)
55
- .map { |polymorphic_type| "#{polymorphic_name}_of_#{polymorphic_type}_type_#{filter.name}" }
56
- .join('_or_')
55
+ .map { |polymorphic_type| "#{polymorphic_name}_of_#{polymorphic_type}_type_#{filter.name}" }
56
+ .join('_or_')
57
57
 
58
58
  "#{name}_#{filter.predicate}"
59
59
  end
@@ -27,7 +27,10 @@ module Might
27
27
 
28
28
  # @raise [NotImplementedError]
29
29
  def get
30
- fail NotImplementedError
30
+ fail NotImplementedError, <<-MESSAGE.strip_heredoc
31
+ #{self.class} does not respond to #get. You should explicitly check for
32
+ #success? before calling #get.
33
+ MESSAGE
31
34
  end
32
35
 
33
36
  # @yield given block
@@ -7,7 +7,7 @@ module Might
7
7
  DIRECTIONS = %w(asc desc).freeze
8
8
  REVERSED_DIRECTIONS = {
9
9
  'asc' => 'desc',
10
- 'desc' => 'asc'
10
+ 'desc' => 'asc',
11
11
  }.freeze
12
12
 
13
13
  attr_reader :direction
@@ -48,7 +48,7 @@ module Might
48
48
  end
49
49
 
50
50
  def undefined?
51
- !self.defined? # rubocop:disable Style/RedundantSelf
51
+ !self.defined?
52
52
  end
53
53
  end
54
54
  end
@@ -1,4 +1,4 @@
1
1
  #
2
2
  module Might
3
- VERSION = '0.6.0'.freeze
3
+ VERSION = '0.7.0'.freeze
4
4
  end
@@ -23,11 +23,12 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'activemodel', '>= 3.2'
24
24
  spec.add_runtime_dependency 'uber', '~> 0.0.15'
25
25
  spec.add_runtime_dependency 'ibsciss-middleware', '~> 0.3'
26
- spec.add_runtime_dependency 'ransack', '~> 1.6.6'
27
- spec.add_development_dependency 'activerecord', '>= 3.2'
28
- spec.add_development_dependency 'sqlite3', '~> 1.3'
29
- spec.add_development_dependency 'bundler', '~> 1.10'
30
- spec.add_development_dependency 'rake', '~> 10.0'
31
- spec.add_development_dependency 'rspec', '~> 3.3'
32
- spec.add_development_dependency 'spbtv_code_style', '~> 1.2.3'
26
+ spec.add_runtime_dependency 'ransack', '>= 1.6.6'
27
+ spec.add_development_dependency 'activerecord', '>= 3.2', '< 6.0.0'
28
+ spec.add_development_dependency 'sqlite3', '~> 1.3.11'
29
+ spec.add_development_dependency 'bundler', '~> 1.12.5'
30
+ spec.add_development_dependency 'rake', '~> 11.2.2'
31
+ spec.add_development_dependency 'rspec', '~> 3.5.0'
32
+ spec.add_development_dependency 'spbtv_code_style', '1.4.1'
33
+ spec.add_development_dependency 'appraisal', '2.1.0'
33
34
  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.6.0
4
+ version: 0.7.0
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-03-24 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: ransack
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.6.6
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.6.6
83
83
  - !ruby/object:Gem::Dependency
@@ -87,6 +87,9 @@ dependencies:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3.2'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: 6.0.0
90
93
  type: :development
91
94
  prerelease: false
92
95
  version_requirements: !ruby/object:Gem::Requirement
@@ -94,76 +97,93 @@ dependencies:
94
97
  - - ">="
95
98
  - !ruby/object:Gem::Version
96
99
  version: '3.2'
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: 6.0.0
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: sqlite3
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
107
  - - "~>"
102
108
  - !ruby/object:Gem::Version
103
- version: '1.3'
109
+ version: 1.3.11
104
110
  type: :development
105
111
  prerelease: false
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
114
  - - "~>"
109
115
  - !ruby/object:Gem::Version
110
- version: '1.3'
116
+ version: 1.3.11
111
117
  - !ruby/object:Gem::Dependency
112
118
  name: bundler
113
119
  requirement: !ruby/object:Gem::Requirement
114
120
  requirements:
115
121
  - - "~>"
116
122
  - !ruby/object:Gem::Version
117
- version: '1.10'
123
+ version: 1.12.5
118
124
  type: :development
119
125
  prerelease: false
120
126
  version_requirements: !ruby/object:Gem::Requirement
121
127
  requirements:
122
128
  - - "~>"
123
129
  - !ruby/object:Gem::Version
124
- version: '1.10'
130
+ version: 1.12.5
125
131
  - !ruby/object:Gem::Dependency
126
132
  name: rake
127
133
  requirement: !ruby/object:Gem::Requirement
128
134
  requirements:
129
135
  - - "~>"
130
136
  - !ruby/object:Gem::Version
131
- version: '10.0'
137
+ version: 11.2.2
132
138
  type: :development
133
139
  prerelease: false
134
140
  version_requirements: !ruby/object:Gem::Requirement
135
141
  requirements:
136
142
  - - "~>"
137
143
  - !ruby/object:Gem::Version
138
- version: '10.0'
144
+ version: 11.2.2
139
145
  - !ruby/object:Gem::Dependency
140
146
  name: rspec
141
147
  requirement: !ruby/object:Gem::Requirement
142
148
  requirements:
143
149
  - - "~>"
144
150
  - !ruby/object:Gem::Version
145
- version: '3.3'
151
+ version: 3.5.0
146
152
  type: :development
147
153
  prerelease: false
148
154
  version_requirements: !ruby/object:Gem::Requirement
149
155
  requirements:
150
156
  - - "~>"
151
157
  - !ruby/object:Gem::Version
152
- version: '3.3'
158
+ version: 3.5.0
153
159
  - !ruby/object:Gem::Dependency
154
160
  name: spbtv_code_style
155
161
  requirement: !ruby/object:Gem::Requirement
156
162
  requirements:
157
- - - "~>"
163
+ - - '='
158
164
  - !ruby/object:Gem::Version
159
- version: 1.2.3
165
+ version: 1.4.1
160
166
  type: :development
161
167
  prerelease: false
162
168
  version_requirements: !ruby/object:Gem::Requirement
163
169
  requirements:
164
- - - "~>"
170
+ - - '='
171
+ - !ruby/object:Gem::Version
172
+ version: 1.4.1
173
+ - !ruby/object:Gem::Dependency
174
+ name: appraisal
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - '='
178
+ - !ruby/object:Gem::Version
179
+ version: 2.1.0
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '='
165
185
  - !ruby/object:Gem::Version
166
- version: 1.2.3
186
+ version: 2.1.0
167
187
  description: Mighty resource fetchers build on top of Ransack gem
168
188
  email:
169
189
  - abolshakov@spbtv.com
@@ -176,6 +196,7 @@ files:
176
196
  - ".rspec"
177
197
  - ".rubocop.yml"
178
198
  - ".travis.yml"
199
+ - Appraisals
179
200
  - CHANGELOG.md
180
201
  - Gemfile
181
202
  - LICENSE
@@ -184,6 +205,10 @@ files:
184
205
  - bin/console
185
206
  - bin/setup
186
207
  - config/locales/en.yml
208
+ - gemfiles/rails_4.2.7_ransack_1.6.6.gemfile
209
+ - gemfiles/rails_4.2.7_ransack_1.8.2.gemfile
210
+ - gemfiles/rails_5.0.0_ransack_1.6.6.gemfile
211
+ - gemfiles/rails_5.0.0_ransack_1.8.2.gemfile
187
212
  - lib/might.rb
188
213
  - lib/might/fetcher.rb
189
214
  - lib/might/fetcher_error.rb
@@ -234,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
259
  version: '0'
235
260
  requirements: []
236
261
  rubyforge_project:
237
- rubygems_version: 2.4.5.1
262
+ rubygems_version: 2.5.1
238
263
  signing_key:
239
264
  specification_version: 4
240
265
  summary: Mighty resource fetchers