responses.rb revision 5cad3e82e8c017bc189c4cecc00541ec19a2a6e2
module OopsRequest::Responses
extend ActiveSupport::Concern
included do
has_many :responses, class_name: 'OopsResponse' do
# must be called with a list of Oops::Respose::Element objects
def create_by_elements(elements)
transaction do
delete_all
elements.each {|e| create_by_element(e) }
end
end
# expects a Oops::Respose::Element
def create_by_element(e)
create! \
code: e.code,
name: e.name,
element_type: e.type,
description: e.description,
affects: e.affects
end
end
end
protected
# executes the request and saves the returned elements
def execute_and_save
responses.create_by_elements(execute)
end
def execute
Oops::Client.request(ontology_version.url)
end
end