scopie 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/scopie/base.rb +20 -7
- data/lib/scopie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07a442d7fcafdca554a27f70362aa4e4cbc7009a
|
4
|
+
data.tar.gz: 831d1f902262956da4adab6441436c116136ad6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34e66bf2569a688a1f59cbf14124fc7dac843969d9b7ad27777b0a3bf92b5e1cafcff6c060bef7ce13b2fd7e5047f39dd70e45e7191745d9c77083404700b4be
|
7
|
+
data.tar.gz: 1c269de633a5197d4a014750272ba284346347075443102aa57629be5775ea0a09c337d7c922a331ea62c263af13fa30b3ef9b8d688db8a257823f08110076c1
|
data/README.md
CHANGED
@@ -80,6 +80,8 @@ Scopie supports several options:
|
|
80
80
|
|
81
81
|
* `:as` - The key in the params hash expected to find the scope. Defaults to the scope name.
|
82
82
|
|
83
|
+
* `:in` - The key in the params hash expected to contain a hash holding scope name as a value.
|
84
|
+
|
83
85
|
* `:default` - Default value for the scope. Whenever supplied the scope is always called.
|
84
86
|
|
85
87
|
## Thanks
|
data/lib/scopie/base.rb
CHANGED
@@ -57,7 +57,9 @@ class Scopie::Base
|
|
57
57
|
|
58
58
|
def scope_value(scope_name, options, hash)
|
59
59
|
key_name = key_name(scope_name, options)
|
60
|
-
|
60
|
+
reduced_hash = reduced_hash(hash, options)
|
61
|
+
|
62
|
+
return coerce_value_type(reduced_hash[key_name], options[:type]) if reduced_hash.key?(key_name)
|
61
63
|
options[:default]
|
62
64
|
end
|
63
65
|
|
@@ -71,16 +73,27 @@ class Scopie::Base
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def scope_applicable?(scope_name, options, hash, method)
|
76
|
+
return false unless method_applicable?(method, options)
|
77
|
+
|
78
|
+
key_name = key_name(scope_name, options)
|
79
|
+
reduced_hash(hash, options).key?(key_name) || options.key?(:default)
|
80
|
+
end
|
81
|
+
|
82
|
+
def reduced_hash(hash, options)
|
83
|
+
return hash unless options.key?(:in)
|
84
|
+
hash.fetch(options[:in], {})
|
85
|
+
end
|
86
|
+
|
87
|
+
def method_applicable?(method, options)
|
88
|
+
return true unless method
|
89
|
+
|
74
90
|
methods_white_list = Array(options[:only])
|
75
91
|
methods_black_list = Array(options[:except])
|
76
92
|
|
77
|
-
if method
|
78
|
-
|
79
|
-
return false if methods_white_list.any? && !methods_white_list.include?(method)
|
80
|
-
end
|
93
|
+
return false if methods_black_list.include?(method)
|
94
|
+
return false if methods_white_list.any? && !methods_white_list.include?(method)
|
81
95
|
|
82
|
-
|
83
|
-
hash.key?(key_name) || options.key?(:default)
|
96
|
+
true
|
84
97
|
end
|
85
98
|
|
86
99
|
def self.reset_scopes_configuration!
|
data/lib/scopie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scopie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Kotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|