Module: ApiResource::Formats
- Defined in:
- lib/api_resource/formats.rb,
lib/api_resource/formats/xml_format.rb,
lib/api_resource/formats/json_format.rb,
lib/api_resource/formats/file_upload_format.rb
Defined Under Namespace
Modules: FileUploadFormat, JsonFormat, XmlFormat Classes: BadFormat
Class Method Summary collapse
-
.[](mime_type_reference) ⇒ Object
Lookup the format class from a mime type reference symbol.
Class Method Details
.[](mime_type_reference) ⇒ Object
Lookup the format class from a mime type reference symbol. Example:
ActiveResource::Formats[:xml] # => ActiveResource::Formats::XmlFormat ActiveResource::Formats[:json] # => ActiveResource::Formats::JsonFormat
13 14 15 16 17 18 19 20 |
# File 'lib/api_resource/formats.rb', line 13 def self.[](mime_type_reference) format_name = ActiveSupport::Inflector.camelize(mime_type_reference.to_s) + "Format" begin ApiResource::Formats.const_get(format_name) rescue NameError => e raise BadFormat.new("#{mime_type_reference} is not a valid format") end end |