Module: CarrierWave::Uploader::Serialization

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/carrierwave/uploader/serialization.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object



15
16
17
# File 'lib/carrierwave/uploader/serialization.rb', line 15

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

#serializable_hash(options = nil) ⇒ Object



11
12
13
# File 'lib/carrierwave/uploader/serialization.rb', line 11

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

#to_json(options = nil) ⇒ Object



19
20
21
# File 'lib/carrierwave/uploader/serialization.rb', line 19

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

#to_xml(options = {}) ⇒ Object



23
24
25
26
# File 'lib/carrierwave/uploader/serialization.rb', line 23

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