scopie 0.4.0 → 0.4.1

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: e4dc1d9c52050baf32e9de66d52508da37b2b6d2
4
- data.tar.gz: 6c5abc0c7f5a27e0784db9607cb1e9331c757788
3
+ metadata.gz: 9763d1719a699707d18532d4dac445432d0dc72a
4
+ data.tar.gz: e07cd13548d2a8936bb148133db3e51b0e8f5922
5
5
  SHA512:
6
- metadata.gz: 86efafe4d7843c496ce6dd6c1b6e13f5600184cec5773e4dd90f087f4edf61df0e1cebf94429f4adb5ee4af62b219e34f8609966ec963428a892383f39e191d1
7
- data.tar.gz: ded02f636fa57c71e24bf0bdc70b17d9ceafa0f58d7f5372db265e1887430cbc9d5f785a3d65dad83fb6a23e46fc730fa0b55a1161d005689663b8bdf2d5bb10
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 apply_scope(scope_name, options, target, hash, method = nil)
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
- return target unless scope_applicable?(scope_name, options, hash, method)
27
+ target
28
+ end
22
29
 
23
- value = scope_value(scope_name, options, hash)
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)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Scopie
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
4
4
  end
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.class.scopes_configuration.each do |scope_name, options|
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scopie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Kotov