mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 22:36:50 +00:00
32 lines
607 B
Ruby
32 lines
607 B
Ruby
module ActiveModel
|
|
class Serializer
|
|
class Config
|
|
def initialize(data = {})
|
|
@data = data
|
|
end
|
|
|
|
def each(&block)
|
|
@data.each(&block)
|
|
end
|
|
|
|
def clear
|
|
@data.clear
|
|
end
|
|
|
|
def method_missing(name, *args)
|
|
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('embed' => :objects) # :nodoc:
|
|
end
|
|
end
|