autoscope 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 661ccab79843a45a4e035d2344ab57cf5fa3e061
4
- data.tar.gz: 6567dd9443bbfa11c1d3a068fe830b264a730639
3
+ metadata.gz: 9fa32721bcb23d20bb00efe3aab051c692a36cfb
4
+ data.tar.gz: f212e562d4430099db1a075e64c86aba0d65acb5
5
5
  SHA512:
6
- metadata.gz: 1f90814d6361ff61977b1cb01e69e3136a9e113aefe58aa8ee1971ef3688e530cb597be19339ce91b6cca6e9cb83b9c15d9e79cd462311d35c3f1d6f941c399e
7
- data.tar.gz: ca2d9a6a6389822275269d369c1ba5ce63d3155c4e2220980a8d2af695cf518720b73512f7a84ab790bb88924dd6295943705558baff313ce753b660ab183c8f
6
+ metadata.gz: ef585e6d62fc8f3b21cf9ffc67e115ce31d648db10f5807d0f7b1b630593aff4864d497326aa5a30e233c2aa67979d7fd09b75ada246fb0eef5177f3f36ff7e5
7
+ data.tar.gz: 294b5c56475d6bb53b7059caafcf00a275374a480c5a0cccc92b4843f64524d6dd2b54f953c0e40468b576f1f4b29bdc3b32e19aef7e5d95556de2ade406d25f
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --color
2
- --format nested
2
+ --format progress
3
3
 
@@ -130,7 +130,7 @@ module Autoscope
130
130
  scope.klass.dynamic_scopes.each_pair do |scope_name, arg_def|
131
131
 
132
132
  # skip scopes that are not defined
133
- next if params[scope_name].blank?
133
+ next if self.blank_param?(params[scope_name])
134
134
 
135
135
  # now apply the arguments
136
136
  args_to_pass = self.get_dynamic_scope_args(
@@ -164,6 +164,16 @@ module Autoscope
164
164
  return scope
165
165
  end
166
166
 
167
+ #
168
+ # Is this data blank?
169
+ #
170
+ # @param data [String, Hash]
171
+ #
172
+ # @return [Boolean]
173
+ def blank_param?(data)
174
+ data.blank? || data.try(:values).try(:all?, &:blank?)
175
+ end
176
+
167
177
  #
168
178
  # Get the appropriate args from dynamic scopes
169
179
  #
@@ -1,3 +1,3 @@
1
1
  module Autoscope
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -19,6 +19,10 @@ module Autoscope
19
19
 
20
20
  Post.class_eval do
21
21
 
22
+ scope :blank_arg_scope, -> user_id {
23
+ where(user_id: user_id)
24
+ }
25
+
22
26
  scope :user_id_scope, -> user_id {
23
27
  where(user_id: user_id)
24
28
  }
@@ -84,15 +88,18 @@ module Autoscope
84
88
  .with('req')
85
89
  .returns(scope)
86
90
 
91
+ scope.expects(:blank_arg_scope).never
92
+
87
93
  Post.add_scopes(
88
94
  {
95
+ blank_arg_scope: { user_id: '' },
89
96
  user_id_scope: { user_id: '1' },
90
97
  two_param_scope: {
91
98
  id1: '1',
92
99
  id2: '2'
93
100
  },
94
101
  vararg_scope: { ids: %w{1 2 3} },
95
- optional_arg_scope: { a: 'req' }
102
+ optional_arg_scope: { a: 'req' },
96
103
  },
97
104
  scope
98
105
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Langevin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-19 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord