mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06: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/config'
|
||||
|
||||
require 'thread'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
include Serializable
|
||||
@ -14,7 +16,9 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def setup
|
||||
yield CONFIG
|
||||
Mutex.new.synchronize do
|
||||
yield CONFIG
|
||||
end
|
||||
end
|
||||
|
||||
def embed(type, options={})
|
||||
|
||||
@ -1,41 +1,31 @@
|
||||
require 'thread'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Config
|
||||
def initialize
|
||||
@data = {}
|
||||
@mutex = Mutex.new
|
||||
def initialize(data = {})
|
||||
@data = data
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
@mutex.synchronize do
|
||||
@data.each(&block)
|
||||
end
|
||||
@data.each(&block)
|
||||
end
|
||||
|
||||
def clear
|
||||
@mutex.synchronize do
|
||||
@data.clear
|
||||
end
|
||||
@data.clear
|
||||
end
|
||||
|
||||
def method_missing(name, *args)
|
||||
@mutex.synchronize do
|
||||
name = name.to_s
|
||||
return @data[name] if @data.include?(name)
|
||||
match = name.match(/\A(.*?)([?=]?)\Z/)
|
||||
case match[2]
|
||||
when "="
|
||||
@data[match[1]] = args.first
|
||||
when "?"
|
||||
!!@data[match[1]]
|
||||
end
|
||||
name = name.to_s
|
||||
return @data[name] if @data.include?(name)
|
||||
match = name.match(/\A(.*?)([?=]?)\Z/)
|
||||
case match[2]
|
||||
when "="
|
||||
@data[match[1]] = args.first
|
||||
when "?"
|
||||
!!@data[match[1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
CONFIG = Config.new
|
||||
CONFIG.embed = :objects
|
||||
CONFIG = Config.new('embed' => :objects) # :nodoc:
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user