Sha256: d91525e38c21a2e698ff39d447fae4972ccaf90cb68a63df5830515b2bcf4c67

Contents?: true

Size: 703 Bytes

Versions: 4

Compression:

Stored size: 703 Bytes

Contents

# encoding: utf-8

require "json"
require "active_support/core_ext/hash"

module CarrierWave
  module Uploader
    module Serialization
      extend ActiveSupport::Concern

      def serializable_hash(options = nil)
        {"url" => url}.merge Hash[versions.map { |name, version| [name, { "url" => version.url }] }]
      end

      def as_json(options=nil)
        Hash[mounted_as || "uploader", serializable_hash]
      end

      def to_json(options=nil)
        JSON.generate(as_json)
      end

      def to_xml(options={})
        merged_options = options.merge(:root => mounted_as || "uploader", :type => 'uploader')
        serializable_hash.to_xml(merged_options)
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
carrierwave-0.11.2 lib/carrierwave/uploader/serialization.rb
carrierwave-0.11.1 lib/carrierwave/uploader/serialization.rb
carrierwave-0.11.0 lib/carrierwave/uploader/serialization.rb
carrierwave-0.10.0 lib/carrierwave/uploader/serialization.rb