2007-09-20 19:18:05 -04:00
|
|
|
module ActiveResource
|
|
|
|
module Formats
|
2009-05-06 03:14:55 -04:00
|
|
|
autoload :XmlFormat, 'active_resource/formats/xml_format'
|
|
|
|
autoload :JsonFormat, 'active_resource/formats/json_format'
|
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
# Lookup the format class from a mime type reference symbol. Example:
|
|
|
|
#
|
|
|
|
# ActiveResource::Formats[:xml] # => ActiveResource::Formats::XmlFormat
|
|
|
|
# ActiveResource::Formats[:json] # => ActiveResource::Formats::JsonFormat
|
|
|
|
def self.[](mime_type_reference)
|
2009-05-06 03:14:55 -04:00
|
|
|
ActiveResource::Formats.const_get(ActiveSupport::Inflector.camelize(mime_type_reference.to_s) + "Format")
|
2007-09-20 19:18:05 -04:00
|
|
|
end
|
2011-05-17 19:30:43 -04:00
|
|
|
|
|
|
|
def self.remove_root(data)
|
|
|
|
if data.is_a?(Hash) && data.keys.size == 1
|
|
|
|
data.values.first
|
|
|
|
else
|
|
|
|
data
|
|
|
|
end
|
|
|
|
end
|
2007-09-20 19:18:05 -04:00
|
|
|
end
|
|
|
|
end
|