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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/serialization_scopes.rb +11 -11
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.8.2
@@ -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
- name = options[:scope].try(:to_sym)
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, :methods, :include
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 to_xml_with_scopes(options = {})
50
- to_xml_without_scopes self.class.scoped_serialization_options(options)
49
+ def to_xml(options = {})
50
+ super self.class.scoped_serialization_options(options)
51
51
  end
52
52
 
53
- def as_json_with_scopes(options = {})
54
- as_json_without_scopes self.class.scoped_serialization_options(options)
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: 61
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 1
10
- version: 0.8.1
9
+ - 2
10
+ version: 0.8.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dimitrij Denissenko