scopie 0.1.0 → 0.2.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/lib/scopie.rb +13 -1
- data/lib/scopie/base.rb +54 -0
- data/lib/scopie/version.rb +2 -1
- metadata +60 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 456860cf0ce3c20ee2d6a89bb0ba08181939072f
|
4
|
+
data.tar.gz: 6b0aec3464b6ebd25bd341906ea62ed025399b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93c363fe5b960d144d0265aaed9fad43a05a27e59aab75403c93d0d0d18aaea42963d31bed4de2edcf57c51f9087421a9fb5cb1773f35eaacafea76d36e6a156
|
7
|
+
data.tar.gz: 7d805e7418acf0cb466371945fceccb86254296217197dc6882736708e9d68e877aed5e4c03e5c34339d9e8d87dfe9ac66ccd628eb3f6f8011d5e314b3decf62
|
data/lib/scopie.rb
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Scopie
|
2
|
-
|
4
|
+
|
5
|
+
require 'scopie/base'
|
6
|
+
|
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
|
13
|
+
end
|
14
|
+
|
3
15
|
end
|
data/lib/scopie/base.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Scopie::Base
|
4
|
+
|
5
|
+
def self.scopes_configuration
|
6
|
+
instance_variable_get(:@scopes_configuration) || {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.has_scope(*scopes, **options)
|
10
|
+
@scopes_configuration ||= {}
|
11
|
+
|
12
|
+
scopes.each do |scope|
|
13
|
+
@scopes_configuration[scope.to_sym] = options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def apply_scope(scope_name, options, target, hash, method = nil)
|
18
|
+
hash ||= {}
|
19
|
+
|
20
|
+
return target unless scope_applicable?(scope_name, options, hash, method)
|
21
|
+
|
22
|
+
value = scope_value(scope_name, options, hash)
|
23
|
+
|
24
|
+
if respond_to?(scope_name)
|
25
|
+
public_send(scope_name, target, value, hash)
|
26
|
+
else
|
27
|
+
target.public_send(scope_name, value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def scope_value(scope_name, options, hash)
|
34
|
+
return hash[scope_name] if hash.has_key?(scope_name)
|
35
|
+
options[:default]
|
36
|
+
end
|
37
|
+
|
38
|
+
def scope_applicable?(scope_name, options, hash, method)
|
39
|
+
methods_white_list = Array(options[:only])
|
40
|
+
methods_black_list = Array(options[:except])
|
41
|
+
|
42
|
+
if method
|
43
|
+
return false if methods_black_list.include?(method)
|
44
|
+
return false if methods_white_list.any? && !methods_white_list.include?(method)
|
45
|
+
end
|
46
|
+
|
47
|
+
hash.has_key?(scope_name) || options.has_key?(:default)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.reset_scopes_configuration!
|
51
|
+
@scopes_configuration = {}
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/lib/scopie/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scopie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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-
|
12
|
-
dependencies:
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
13
69
|
description: Minimal mapping of incoming parameters to named scopes in your resources
|
14
70
|
through OO design and pure Ruby classes
|
15
71
|
email:
|
@@ -21,6 +77,7 @@ files:
|
|
21
77
|
- LICENSE
|
22
78
|
- README.md
|
23
79
|
- lib/scopie.rb
|
80
|
+
- lib/scopie/base.rb
|
24
81
|
- lib/scopie/version.rb
|
25
82
|
homepage: https://github.com/beorc/scopie
|
26
83
|
licenses:
|