scopie 0.4.0 → 0.4.1
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/lib/scopie/base.rb +23 -6
- data/lib/scopie/version.rb +1 -1
- data/lib/scopie.rb +1 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9763d1719a699707d18532d4dac445432d0dc72a
|
4
|
+
data.tar.gz: e07cd13548d2a8936bb148133db3e51b0e8f5922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f920328cb50abe0e4131762311b0111a203b730c5ff40ae909e51b4f8a5265a5c51ee7516ec7be01cdb55249d52f55de49aac612a4b2c57ab3c84a7bcf1b1ee
|
7
|
+
data.tar.gz: 8fea91b733869caaa7b4940249a009c16fb73993253401728b84883d128f94123d1fbaec051ae5aa1ffe3c7edc52032a2b9997f0f621d320c4abe1dcb57fa382
|
data/lib/scopie/base.rb
CHANGED
@@ -7,6 +7,10 @@ class Scopie::Base
|
|
7
7
|
instance_variable_get(:@scopes_configuration) || {}
|
8
8
|
end
|
9
9
|
|
10
|
+
def scopes_configuration
|
11
|
+
self.class.scopes_configuration
|
12
|
+
end
|
13
|
+
|
10
14
|
def self.has_scope(*scopes, **options)
|
11
15
|
@scopes_configuration ||= {}
|
12
16
|
|
@@ -15,13 +19,28 @@ class Scopie::Base
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
19
|
-
hash
|
22
|
+
def apply_scopes(target, hash, method = nil)
|
23
|
+
current_scopes(hash, method).each do |scope_name, value|
|
24
|
+
target = apply_scope(scope_name, target, value, hash)
|
25
|
+
end
|
20
26
|
|
21
|
-
|
27
|
+
target
|
28
|
+
end
|
22
29
|
|
23
|
-
|
30
|
+
def current_scopes(hash, method = nil)
|
31
|
+
scopes = scopes_configuration.map do |scope_name, options|
|
32
|
+
next unless scope_applicable?(scope_name, options, hash, method)
|
33
|
+
value = scope_value(scope_name, options, hash)
|
34
|
+
[scope_name, value]
|
35
|
+
end
|
24
36
|
|
37
|
+
scopes.compact!
|
38
|
+
scopes
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def apply_scope(scope_name, target, value, hash)
|
25
44
|
if respond_to?(scope_name)
|
26
45
|
public_send(scope_name, target, value, hash)
|
27
46
|
else
|
@@ -29,8 +48,6 @@ class Scopie::Base
|
|
29
48
|
end
|
30
49
|
end
|
31
50
|
|
32
|
-
private
|
33
|
-
|
34
51
|
def key_name(scope_name, options)
|
35
52
|
key_name = scope_name
|
36
53
|
key_name = options[:as] if options.key?(:as)
|
data/lib/scopie/version.rb
CHANGED
data/lib/scopie.rb
CHANGED
@@ -5,11 +5,7 @@ module Scopie
|
|
5
5
|
require 'scopie/base'
|
6
6
|
|
7
7
|
def self.apply_scopes(target, hash, method: nil, scopie: Scopie::Base.new)
|
8
|
-
scopie.
|
9
|
-
target = scopie.apply_scope(scope_name, options, target, hash, method)
|
10
|
-
end
|
11
|
-
|
12
|
-
target
|
8
|
+
scopie.apply_scopes(target, hash, method)
|
13
9
|
end
|
14
10
|
|
15
11
|
end
|