serialization_scopes 0.8.2 → 0.9.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.2
1
+ 0.9.0
@@ -1,14 +1,17 @@
1
+ require 'serialization_scopes/resolver'
2
+
1
3
  module SerializationScopes
2
4
  extend ActiveSupport::Concern
3
5
 
4
6
  included do
5
- class_inheritable_accessor :serialization_scopes, :instance_reader => false, :instance_writer => false
7
+ class_inheritable_reader :serialization_scopes, :instance_reader => false
8
+ write_inheritable_attribute :serialization_scopes, {}
6
9
  end
7
10
 
8
11
  module ClassMethods
9
12
 
10
13
  def serialization_scope(name, options = {})
11
- self.serialization_scopes ||= {}
14
+ include InstanceExtensions unless included_modules.include?(InstanceExtensions)
12
15
  serialization_scopes[name.to_sym] = options
13
16
  end
14
17
 
@@ -25,35 +28,18 @@ module SerializationScopes
25
28
 
26
29
  end
27
30
 
28
- module Resolver
29
-
30
- def self.scope(key, defaults, settings)
31
- defaults = Array.wrap(defaults).map(&:to_s)
32
- settings = Array.wrap(settings).map(&:to_s)
31
+ module InstanceExtensions
32
+ extend ActiveSupport::Concern
33
33
 
34
- case key
35
- when :except
36
- (settings + defaults).uniq
37
- when :only
38
- result = settings & defaults
39
- result.empty? ? defaults : result
40
- when :methods, :include
41
- settings & defaults
42
- else
43
- settings
44
- end
34
+ def to_xml(options = {})
35
+ super self.class.scoped_serialization_options(options)
45
36
  end
46
37
 
47
- end
48
-
49
- def to_xml(options = {})
50
- super self.class.scoped_serialization_options(options)
51
- end
38
+ def serializable_hash(options = {})
39
+ super self.class.scoped_serialization_options(options)
40
+ end
52
41
 
53
- def serializable_hash(options = {})
54
- super self.class.scoped_serialization_options(options)
55
42
  end
56
-
57
43
  end
58
44
 
59
45
  ActiveRecord::Base.class_eval do
@@ -0,0 +1,23 @@
1
+ module SerializationScopes
2
+ module Resolver
3
+ extend self
4
+
5
+ def scope(key, defaults, settings)
6
+ defaults = Array.wrap(defaults).map(&:to_s)
7
+ settings = Array.wrap(settings).map(&:to_s)
8
+
9
+ case key
10
+ when :except
11
+ (settings + defaults).uniq
12
+ when :only
13
+ result = settings & defaults
14
+ result.empty? ? defaults : result
15
+ when :methods, :include
16
+ settings & defaults
17
+ else
18
+ settings
19
+ end
20
+ end
21
+
22
+ end
23
+ end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
9
- - 2
10
- version: 0.8.2
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dimitrij Denissenko
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-20 00:00:00 +01:00
19
+ date: 2011-04-21 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
@@ -32,6 +32,7 @@ files:
32
32
  - VERSION
33
33
  - README
34
34
  - lib/serialization_scopes.rb
35
+ - lib/serialization_scopes/resolver.rb
35
36
  - lib/serialization_scopes/matchers/serialize_matcher.rb
36
37
  - lib/serialization_scopes/matchers.rb
37
38
  - rails/init.rb