mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Move synchronize to setup method and make CONFIG private
This commit is contained in:
parent
dc33dac56b
commit
b44e1af5dd
@ -3,6 +3,8 @@ require 'active_model/serializable'
|
|||||||
require 'active_model/serializer/associations'
|
require 'active_model/serializer/associations'
|
||||||
require 'active_model/serializer/config'
|
require 'active_model/serializer/config'
|
||||||
|
|
||||||
|
require 'thread'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
include Serializable
|
include Serializable
|
||||||
@ -14,8 +16,10 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
Mutex.new.synchronize do
|
||||||
yield CONFIG
|
yield CONFIG
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def embed(type, options={})
|
def embed(type, options={})
|
||||||
CONFIG.embed = type
|
CONFIG.embed = type
|
||||||
|
|||||||
@ -1,27 +1,19 @@
|
|||||||
require 'thread'
|
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class Config
|
class Config
|
||||||
def initialize
|
def initialize(data = {})
|
||||||
@data = {}
|
@data = data
|
||||||
@mutex = Mutex.new
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
@mutex.synchronize do
|
|
||||||
@data.each(&block)
|
@data.each(&block)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def clear
|
def clear
|
||||||
@mutex.synchronize do
|
|
||||||
@data.clear
|
@data.clear
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def method_missing(name, *args)
|
def method_missing(name, *args)
|
||||||
@mutex.synchronize do
|
|
||||||
name = name.to_s
|
name = name.to_s
|
||||||
return @data[name] if @data.include?(name)
|
return @data[name] if @data.include?(name)
|
||||||
match = name.match(/\A(.*?)([?=]?)\Z/)
|
match = name.match(/\A(.*?)([?=]?)\Z/)
|
||||||
@ -33,9 +25,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
CONFIG = Config.new
|
CONFIG = Config.new('embed' => :objects) # :nodoc:
|
||||||
CONFIG.embed = :objects
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user