Sha256: 4ca356a2a9239de21797adfdf277b34098a307fcb586c166f950b2ae71894a4b

Contents?: true

Size: 787 Bytes

Versions: 10

Compression:

Stored size: 787 Bytes

Contents

# frozen_string_literal: true

module ActiveResource
  module Formats
    autoload :XmlFormat, "#{__dir__}/formats/xml_format.rb"
    autoload :JsonFormat, "#{__dir__}/formats/json_format.rb"

    # 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)
      ActiveResource::Formats.const_get(ActiveSupport::Inflector.camelize(mime_type_reference.to_s) + "Format")
    end

    def self.remove_root(data)
      if data.is_a?(Hash) && data.keys.size == 1 && data.values.first.is_a?(Enumerable)
        data.values.first
      else
        data
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active_cached_resource-0.1.8 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.1.7 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.1.6 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.1.5 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.1.4 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.1.3 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.1.2 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.1.1 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.1.0 lib/activeresource/lib/active_resource/formats.rb
active_cached_resource-0.0.1.pre lib/activeresource/lib/active_resource/formats.rb