scopable 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +10 -9
- data/.travis.yml +1 -1
- data/README.md +5 -5
- data/lib/scopable.rb +3 -0
- data/lib/scopable/version.rb +1 -1
- data/scopable.gemspec +1 -0
- data/test/scopable_test.rb +30 -6
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5a3bcc2de0db35befe93021d9db35d31618e6040bfada9e0b3a2073290503280
|
4
|
+
data.tar.gz: 22eb8fc269eef1a7ea07e8902d5ac4dc6af46663a6bdeecedd77ff95e969fe2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51a2bd239421d72d8180f8137d0aec49eaaf68f5f7815c41ad204f6ccbb3158e9eb3dbe02fea4f6c5af4188a0004c4664a82272366fda4eb80dac59e5c6c5f9d
|
7
|
+
data.tar.gz: 336818370d75470b375595be0494a2dfcc6aa3ec24d6efc47c26fad209f6f2dc945027279a3b0f59d760f54d83133d7b2d20072d305bd88ace12e7b3aab057d1
|
data/.codeclimate.yml
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
|
1
|
+
version: "2"
|
2
|
+
plugins:
|
2
3
|
rubocop:
|
3
4
|
enabled: true
|
4
|
-
|
5
|
+
checks:
|
6
|
+
method-lines:
|
5
7
|
enabled: true
|
6
8
|
config:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
- test/**/*
|
9
|
+
threshold: 40
|
10
|
+
method-complexity:
|
11
|
+
config:
|
12
|
+
threshold: 40
|
13
|
+
exclude_patterns:
|
14
|
+
- "test/"
|
data/.travis.yml
CHANGED
@@ -4,7 +4,7 @@ env:
|
|
4
4
|
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
|
5
5
|
language: ruby
|
6
6
|
rvm:
|
7
|
-
- 2.
|
7
|
+
- 2.5.1
|
8
8
|
before_script:
|
9
9
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
10
10
|
- chmod +x ./cc-test-reporter
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
[![RubyGems](https://img.shields.io/gem/dt/scopable.svg?style=flat)](https://rubygems.org/gems/scopable)
|
2
|
-
[![Build](https://img.shields.io/travis/corenzan/scopable.svg?style=flat)](https://travis-ci.org/corenzan/scopable)
|
3
|
-
[![
|
4
|
-
[![Test Coverage](https://img.shields.io/codeclimate/
|
1
|
+
[![RubyGems](https://img.shields.io/gem/dt/scopable.svg?style=flat-square)](https://rubygems.org/gems/scopable)
|
2
|
+
[![Build](https://img.shields.io/travis/corenzan/scopable.svg?style=flat-square)](https://travis-ci.org/corenzan/scopable)
|
3
|
+
[![Maintainability](https://img.shields.io/codeclimate/maintainability/corenzan/scopable.svg?style=flat-square)](https://codeclimate.com/github/corenzan/scopable/maintainability)
|
4
|
+
[![Test Coverage](https://img.shields.io/codeclimate/c/corenzan/scopable.svg?style=flat-square)](https://codeclimate.com/github/corenzan/scopable/test_coverage)
|
5
5
|
|
6
6
|
# Scopable
|
7
7
|
|
@@ -99,7 +99,7 @@ Key | Description
|
|
99
99
|
`:required` | Calls `#none` on the model if parameter is absent (blank or nil) and there's no default value set.
|
100
100
|
`:if` | ...
|
101
101
|
`:unless` | ...
|
102
|
-
`&block` | Block will be
|
102
|
+
`&block` | Block will be executed in the context of the relation plus two local methods `value` and `params`.
|
103
103
|
|
104
104
|
## Collaboration
|
105
105
|
|
data/lib/scopable.rb
CHANGED
@@ -62,6 +62,9 @@ class Scopable
|
|
62
62
|
next relation if delegator(relation, value, params).instance_exec(&options[:unless])
|
63
63
|
end
|
64
64
|
|
65
|
+
# Bail if the value is false or nil.
|
66
|
+
next relation if !value
|
67
|
+
|
65
68
|
# When a block is present, use that, otherwise call the scope method.
|
66
69
|
if options[:block].present?
|
67
70
|
delegator(relation, value, params).instance_exec(&options[:block])
|
data/lib/scopable/version.rb
CHANGED
data/scopable.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'activesupport', '~> 5.0'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
26
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
26
27
|
spec.add_development_dependency 'minitest', '~> 5.10'
|
27
28
|
spec.add_development_dependency 'rubocop', '~> 0.49'
|
28
29
|
spec.add_development_dependency 'simplecov', '~> 0.14'
|
data/test/scopable_test.rb
CHANGED
@@ -74,7 +74,7 @@ class ScopableTest < Minitest::Test
|
|
74
74
|
refute_scope(scopable.resolve, :fuzzy)
|
75
75
|
end
|
76
76
|
|
77
|
-
test 'matching param with
|
77
|
+
test 'matching param with truthy value' do
|
78
78
|
model = Model.new
|
79
79
|
scopable = Scopable.new(model, fuzzy: {})
|
80
80
|
assert_scope(scopable.resolve(fuzzy: 'on'), :fuzzy, true)
|
@@ -82,12 +82,12 @@ class ScopableTest < Minitest::Test
|
|
82
82
|
assert_scope(scopable.resolve(fuzzy: 'true'), :fuzzy, true)
|
83
83
|
end
|
84
84
|
|
85
|
-
test 'matching param with
|
85
|
+
test 'matching param with falsey value' do
|
86
86
|
model = Model.new
|
87
87
|
scopable = Scopable.new(model, fuzzy: {})
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
refute_scope(scopable.resolve(fuzzy: 'no'), :fuzzy)
|
89
|
+
refute_scope(scopable.resolve(fuzzy: 'off'), :fuzzy)
|
90
|
+
refute_scope(scopable.resolve(fuzzy: 'false'), :fuzzy)
|
91
91
|
end
|
92
92
|
|
93
93
|
test 'param option' do
|
@@ -137,10 +137,34 @@ class ScopableTest < Minitest::Test
|
|
137
137
|
assert_scope(scopable.resolve(params), :fuzzy, 'fuzzy')
|
138
138
|
end
|
139
139
|
|
140
|
-
test 'block option' do
|
140
|
+
test 'block option matching' do
|
141
141
|
model = Model.new
|
142
142
|
scopable = Scopable.new(model, fuzzy: { block: -> { jumbo(value) } })
|
143
143
|
params = { fuzzy: 'fuzzy' }
|
144
144
|
assert_scope(scopable.resolve(params), :jumbo, 'fuzzy')
|
145
145
|
end
|
146
|
+
|
147
|
+
test 'block option miss' do
|
148
|
+
model = Model.new
|
149
|
+
scopable = Scopable.new(model, fuzzy: { block: -> { jumbo(value) } })
|
150
|
+
params = {}
|
151
|
+
refute_scope(scopable.resolve(params), :jumbo)
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'block option with falsey value' do
|
155
|
+
model = Model.new
|
156
|
+
scopable = Scopable.new(model, fuzzy: { block: -> { jumbo(value) } })
|
157
|
+
params = { fuzzy: false }
|
158
|
+
refute_scope(scopable.resolve(params), :jumbo)
|
159
|
+
end
|
160
|
+
|
161
|
+
test 'block delegator' do
|
162
|
+
model = Model.new
|
163
|
+
params = { fuzzy: 'fuzzy' }
|
164
|
+
scopable = Scopable.new(model, {})
|
165
|
+
delegator = scopable.delegator(model, 'fuzzy', params)
|
166
|
+
assert_respond_to(delegator, :all)
|
167
|
+
assert_equal('fuzzy', delegator.value)
|
168
|
+
assert_equal(params, delegator.params)
|
169
|
+
end
|
146
170
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scopable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Corenzan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: minitest
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
135
|
version: '0'
|
122
136
|
requirements: []
|
123
137
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.6
|
138
|
+
rubygems_version: 2.7.6
|
125
139
|
signing_key:
|
126
140
|
specification_version: 4
|
127
141
|
summary: Easy parametric query building in Rails.
|