24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/deltacloud/helpers/conversion_helper.rb', line 24
def convert_to_json(type, obj)
if ( [ :flavor, :account, :image, :realm, :instance, :storage_volume, :storage_snapshot, :hardware_profile ].include?( type ) )
if Array.eql?(obj.class)
data = obj.collect do |o|
o.to_hash.merge({ :href => self.send(:"#{type}_url", type.eql?(:hardware_profile) ? o.name : o.id ) })
end
type = type.to_s.pluralize
else
data = obj.to_hash
data.merge!({ :href => self.send(:"#{type}_url", data[:id]) })
end
return { :"#{type}" => data }.to_json
end
end
|