File tree Expand file tree Collapse file tree 3 files changed +30
-32
lines changed Expand file tree Collapse file tree 3 files changed +30
-32
lines changed Original file line number Diff line number Diff line change
1
+ require 'active_model/serializable/utils'
2
+
1
3
module ActiveModel
2
4
module Serializable
5
+ def self . included ( base )
6
+ base . extend Utils
7
+ end
8
+
3
9
def as_json ( options = { } )
4
10
instrument ( '!serialize' ) do
5
11
if root = options . fetch ( :root , json_key )
@@ -26,14 +32,8 @@ def serializable_data
26
32
end
27
33
end
28
34
29
- if RUBY_VERSION >= '2.0'
30
- def namespace
31
- get_namespace && Object . const_get ( get_namespace )
32
- end
33
- else
34
- def namespace
35
- get_namespace && get_namespace . safe_constantize
36
- end
35
+ def namespace
36
+ get_namespace && Utils . _const_get ( get_namespace )
37
37
end
38
38
39
39
def embedded_in_root_associations
Original file line number Diff line number Diff line change
1
+ module ActiveModel
2
+ module Serializable
3
+ module Utils
4
+ extend self
5
+
6
+ def _const_get ( const )
7
+ method = RUBY_VERSION >= '2.0' ? :const_get : :qualified_const_get
8
+ Object . send method , const
9
+ end
10
+ end
11
+ end
12
+ end
Original file line number Diff line number Diff line change @@ -55,32 +55,18 @@ def format_keys(format)
55
55
end
56
56
attr_reader :key_format
57
57
58
- if RUBY_VERSION >= '2.0'
59
- def serializer_for ( resource , options = { } )
60
- if resource . respond_to? ( :to_ary )
61
- if Object . constants . include? ( :ArraySerializer )
62
- ::ArraySerializer
63
- else
64
- ArraySerializer
65
- end
58
+ def serializer_for ( resource , options = { } )
59
+ if resource . respond_to? ( :to_ary )
60
+ if Object . constants . include? ( :ArraySerializer )
61
+ ::ArraySerializer
66
62
else
67
- begin
68
- Object . const_get build_serializer_class ( resource , options )
69
- rescue NameError
70
- nil
71
- end
63
+ ArraySerializer
72
64
end
73
- end
74
- else
75
- def serializer_for ( resource , options = { } )
76
- if resource . respond_to? ( :to_ary )
77
- if Object . constants . include? ( :ArraySerializer )
78
- ::ArraySerializer
79
- else
80
- ArraySerializer
81
- end
82
- else
83
- build_serializer_class ( resource , options ) . safe_constantize
65
+ else
66
+ begin
67
+ _const_get build_serializer_class ( resource , options )
68
+ rescue NameError
69
+ nil
84
70
end
85
71
end
86
72
end
You can’t perform that action at this time.
0 commit comments