mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
fix for ruby 1.9.
This commit is contained in:
parent
493041fdff
commit
095bae31d4
@ -1,5 +1,11 @@
|
||||
require 'active_model/serializable/utils'
|
||||
|
||||
module ActiveModel
|
||||
module Serializable
|
||||
def self.included(base)
|
||||
base.extend Utils
|
||||
end
|
||||
|
||||
def as_json(options={})
|
||||
instrument('!serialize') do
|
||||
if root = options.fetch(:root, json_key)
|
||||
@ -26,14 +32,8 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
if RUBY_VERSION >= '2.0'
|
||||
def namespace
|
||||
get_namespace && Object.const_get(get_namespace)
|
||||
end
|
||||
else
|
||||
def namespace
|
||||
get_namespace && get_namespace.safe_constantize
|
||||
end
|
||||
def namespace
|
||||
get_namespace && Utils._const_get(get_namespace)
|
||||
end
|
||||
|
||||
def embedded_in_root_associations
|
||||
|
||||
12
lib/active_model/serializable/utils.rb
Normal file
12
lib/active_model/serializable/utils.rb
Normal file
@ -0,0 +1,12 @@
|
||||
module ActiveModel
|
||||
module Serializable
|
||||
module Utils
|
||||
extend self
|
||||
|
||||
def _const_get(const)
|
||||
method = RUBY_VERSION >= '2.0' ? :const_get : :qualified_const_get
|
||||
Object.send method, const
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -55,32 +55,18 @@ end
|
||||
end
|
||||
attr_reader :key_format
|
||||
|
||||
if RUBY_VERSION >= '2.0'
|
||||
def serializer_for(resource, options = {})
|
||||
if resource.respond_to?(:to_ary)
|
||||
if Object.constants.include?(:ArraySerializer)
|
||||
::ArraySerializer
|
||||
else
|
||||
ArraySerializer
|
||||
end
|
||||
def serializer_for(resource, options = {})
|
||||
if resource.respond_to?(:to_ary)
|
||||
if Object.constants.include?(:ArraySerializer)
|
||||
::ArraySerializer
|
||||
else
|
||||
begin
|
||||
Object.const_get build_serializer_class(resource, options)
|
||||
rescue NameError
|
||||
nil
|
||||
end
|
||||
ArraySerializer
|
||||
end
|
||||
end
|
||||
else
|
||||
def serializer_for(resource, options = {})
|
||||
if resource.respond_to?(:to_ary)
|
||||
if Object.constants.include?(:ArraySerializer)
|
||||
::ArraySerializer
|
||||
else
|
||||
ArraySerializer
|
||||
end
|
||||
else
|
||||
build_serializer_class(resource, options).safe_constantize
|
||||
else
|
||||
begin
|
||||
_const_get build_serializer_class(resource, options)
|
||||
rescue NameError
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user