У меня есть объект, который имеет функцию to_builder
, чтобы иметь возможность создавать JSON на лету, который работает.Проблема возникает, когда я хочу включить другой объект, который также имеет метод to_builder
.
Первый класс:
class Discovery
def initialize(shower)
@shower = shower
end
def to_builder
Jbuilder.new do |json|
json.friendlyName @shower.name
json.displayCategories ['OTHER']
json.cookie {}
json.capabilities do
json.child! do
json.type 'AlexaInterface'
json.interface 'Alexa'
json.version '3'
end
Discovery::CustomIntent.new.to_builder.target!
json.child!{Discovery::CustomIntent.new.to_builder}
end
end
end
end
Второй класс:
class Discovery::CustomIntent
def initialize
@intents = %w(ShowerName ShowerOn ShowerOff ShowerPreset AMAZON.CancelIntent AMAZON.HelpIntent AMAZON.StopIntent)
end
def to_builder
Jbuilder.new do |json|
json.type 'AlexaInterface'
json.interface 'Alexa.CustomIntent'
json.version '3'
json.configuration do
json.supportedIntents do
json.(@intents) do |intent|
json.name intent
end
end
end
end
end
end
Всякий раз, когда я делаю что-то вроде Discovery.new(shower).to_builder.target!
, внутренний объект, который я пытаюсь добавить, всегда просто пуст.
"{\"friendlyName\":\"Demo Shower\",\"displayCategories\":[\"OTHER\"],\"capabilities\":[{\"type\":\"AlexaInterface\",\"interface\":\"Alexa\",\"version\":\"3\"},{}]}"