# File lib/cimi/models/schema.rb, line 299 def initialize(name, opts = {}) params = {} params[:scope] = opts.delete(:scope) super(name, opts) unless opts[:class] raise "Specify the class of collection entries using :class" end params[:embedded] = true unless opts[:class].collection_class opts[:class].collection_class = CIMI::Model::Collection.generate(opts[:class], params) end @collection_class = opts[:class].collection_class end
# File lib/cimi/models/schema.rb, line 319 def from_json(json, model) if json[json_name] model[name] = @collection_class.schema.from_json(json[json_name], {}) end end
# File lib/cimi/models/schema.rb, line 313 def from_xml(xml, model) if xml[xml_name] model[name] = @collection_class.schema.from_xml(xml[xml_name].first, {}) end end
# File lib/cimi/models/schema.rb, line 335 def to_json(model, json) return if model[name].nil? model[name].prepare if model[name].entries.empty? json[json_name] = { "href" => model[name].href } else json[json_name] = @collection_class.schema.to_json(model[name]) end end
# File lib/cimi/models/schema.rb, line 325 def to_xml(model, xml) return if model[name].nil? model[name].prepare if model[name].entries.empty? xml[xml_name] = { "href" => model[name].href } else xml[xml_name] = @collection_class.schema.to_xml(model[name]) end end