serialization_scopes 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/serialization_scopes.rb +11 -11
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.2
|
data/lib/serialization_scopes.rb
CHANGED
@@ -3,8 +3,6 @@ module SerializationScopes
|
|
3
3
|
|
4
4
|
included do
|
5
5
|
class_inheritable_accessor :serialization_scopes, :instance_reader => false, :instance_writer => false
|
6
|
-
alias_method_chain :to_xml, :scopes
|
7
|
-
alias_method_chain :as_json, :scopes
|
8
6
|
end
|
9
7
|
|
10
8
|
module ClassMethods
|
@@ -16,8 +14,7 @@ module SerializationScopes
|
|
16
14
|
|
17
15
|
def scoped_serialization_options(options = {})
|
18
16
|
options = options.try(:clone) || {}
|
19
|
-
|
20
|
-
scopes = name.present? && serialization_scopes.key?(name) ? serialization_scopes[name] : serialization_scopes[:default]
|
17
|
+
scopes = (serialization_scopes[options[:scope]] || serialization_scopes[:default]) unless options[:scope] == false
|
21
18
|
|
22
19
|
scopes.each do |key, defaults|
|
23
20
|
options[key] = options[key] ? Resolver.scope(key, defaults, options[key]) : defaults
|
@@ -31,13 +28,16 @@ module SerializationScopes
|
|
31
28
|
module Resolver
|
32
29
|
|
33
30
|
def self.scope(key, defaults, settings)
|
34
|
-
defaults = Array.wrap(defaults)
|
35
|
-
settings = Array.wrap(settings)
|
31
|
+
defaults = Array.wrap(defaults).map(&:to_s)
|
32
|
+
settings = Array.wrap(settings).map(&:to_s)
|
36
33
|
|
37
34
|
case key
|
38
35
|
when :except
|
39
36
|
(settings + defaults).uniq
|
40
|
-
when :only
|
37
|
+
when :only
|
38
|
+
result = settings & defaults
|
39
|
+
result.empty? ? defaults : result
|
40
|
+
when :methods, :include
|
41
41
|
settings & defaults
|
42
42
|
else
|
43
43
|
settings
|
@@ -46,12 +46,12 @@ module SerializationScopes
|
|
46
46
|
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
|
49
|
+
def to_xml(options = {})
|
50
|
+
super self.class.scoped_serialization_options(options)
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
54
|
-
|
53
|
+
def serializable_hash(options = {})
|
54
|
+
super self.class.scoped_serialization_options(options)
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serialization_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 2
|
10
|
+
version: 0.8.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dimitrij Denissenko
|