mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
42 lines
784 B
Ruby
42 lines
784 B
Ruby
require 'thread'
|
|
|
|
module ActiveModel
|
|
class Serializer
|
|
class Config
|
|
def initialize
|
|
@data = {}
|
|
@mutex = Mutex.new
|
|
end
|
|
|
|
def each(&block)
|
|
@mutex.synchronize do
|
|
@data.each(&block)
|
|
end
|
|
end
|
|
|
|
def clear
|
|
@mutex.synchronize do
|
|
@data.clear
|
|
end
|
|
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
|
|
end
|
|
end
|
|
end
|
|
|
|
CONFIG = Config.new
|
|
CONFIG.embed = :objects
|
|
end
|
|
end
|