nifty_scope 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +7 -3
- data/lib/nifty_scope/scope.rb +9 -3
- data/lib/nifty_scope/version.rb +1 -1
- data/spec/nifty_scope/nifty_scope_spec.rb +38 -0
- metadata +25 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c148c4b9f79230e3d26591f1e5dfe0e8f8371edf
|
4
|
+
data.tar.gz: 67278babca483409f837b6f3c2803f6c0dc3d1cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cd20e6db68f1c20e02e067263ed3528aa47a326b8c771a89eefc18e70fe5864cf82d201d139de620eee89851b719139c69721c3752d534ee99d4e30cf6d19d5
|
7
|
+
data.tar.gz: b06f7f6b31a7c02fbb1be2be367870b28178bc77674a32d7959272b9253c86564d086994d60d1b2a1cabc2bac5d5e86739078021d32c1c4fd473aa480fe0ac65
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -2,12 +2,16 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
gem 'pry'
|
6
|
+
gem 'byebug'
|
7
|
+
gem 'pry-byebug'
|
8
|
+
|
5
9
|
group :test, :development do
|
6
10
|
gem 'pre-commit'
|
7
11
|
gem 'cane'
|
8
12
|
end
|
9
13
|
|
10
|
-
group :
|
11
|
-
gem '
|
12
|
-
gem '
|
14
|
+
group :test do
|
15
|
+
gem 'coveralls', require: false
|
16
|
+
gem 'codeclimate-test-reporter', require: false
|
13
17
|
end
|
data/lib/nifty_scope/scope.rb
CHANGED
@@ -13,7 +13,7 @@ module NiftyScope
|
|
13
13
|
scope_method = scope_method_for(key.to_sym)
|
14
14
|
ensure_scope_responds_to(scope_method)
|
15
15
|
|
16
|
-
@scope = eval_scope(scope_method,
|
16
|
+
@scope = eval_scope(scope_method, value)
|
17
17
|
end
|
18
18
|
|
19
19
|
@scope
|
@@ -23,9 +23,15 @@ module NiftyScope
|
|
23
23
|
|
24
24
|
def eval_scope(method, args)
|
25
25
|
if method.is_a?(Proc)
|
26
|
-
|
26
|
+
if method.arity > 0
|
27
|
+
@scope.instance_exec(*args, &method)
|
28
|
+
elsif args
|
29
|
+
@scope.instance_exec(&method)
|
30
|
+
else
|
31
|
+
@scope
|
32
|
+
end
|
27
33
|
else
|
28
|
-
@scope.send(method, *args)
|
34
|
+
@scope.send(method, *scope_args(args))
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
data/lib/nifty_scope/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pry-byebug'
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe NiftyScope do
|
@@ -22,6 +23,43 @@ describe NiftyScope do
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
26
|
+
context 'with mappings to boolean scope' do
|
27
|
+
let!(:paramsless_deers) do
|
28
|
+
Deer.nifty_scope(params, mapping: {
|
29
|
+
is_alive: -> { alive }
|
30
|
+
})
|
31
|
+
end
|
32
|
+
let!(:paramsfull_deers) do
|
33
|
+
Deer.nifty_scope(params, mapping: {
|
34
|
+
is_alive: ->(value) { value ? alive : dead }
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'show me alive deers' do
|
39
|
+
let!(:params) { { is_alive: true } }
|
40
|
+
|
41
|
+
it 'should return two alive deers with parameterfull mapping' do
|
42
|
+
expect(paramsfull_deers.count).to eq(2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return two alive deers with parameterless mapping' do
|
46
|
+
expect(paramsless_deers.count).to eq(2)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'show me dead deers' do
|
51
|
+
let!(:params) { { is_alive: false} }
|
52
|
+
|
53
|
+
it 'should return two alive deers with parameterfull mapping' do
|
54
|
+
expect(paramsfull_deers.count).to eq(1)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should return two alive deers with parameterless mapping' do
|
58
|
+
expect(paramsless_deers.count).to eq(3)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
25
63
|
context 'with parameterless scope' do
|
26
64
|
let!(:params) { { :dead => true } }
|
27
65
|
|
metadata
CHANGED
@@ -1,149 +1,149 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nifty_scope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliy Yorkin, Alexandr Shuhin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.5'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
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: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: factory_girl
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: factory_girl_sequences
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: database_cleaner
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description:
|
139
|
+
description: " Provides an easy way to map request parameters to scopes "
|
140
140
|
email:
|
141
141
|
- vasiliy.yorkin@gmail.com
|
142
142
|
executables: []
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
-
- .gitignore
|
146
|
+
- ".gitignore"
|
147
147
|
- Gemfile
|
148
148
|
- LICENSE
|
149
149
|
- README.md
|
@@ -168,17 +168,17 @@ require_paths:
|
|
168
168
|
- lib
|
169
169
|
required_ruby_version: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- -
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
175
|
requirements:
|
176
|
-
- -
|
176
|
+
- - ">="
|
177
177
|
- !ruby/object:Gem::Version
|
178
178
|
version: '0'
|
179
179
|
requirements: []
|
180
180
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.2.
|
181
|
+
rubygems_version: 2.2.0
|
182
182
|
signing_key:
|
183
183
|
specification_version: 4
|
184
184
|
summary: Provides an easy way to map request parameters to scopes
|