Sha256: a2cad5456909de7d081fe83abaac5754d6efc55448f3a1c70bddafdfb0168ddf
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
module RailsConnector class CmsRestApi module AttributeSerializer class << self def convert(attributes) Hash[ attributes.map do |attribute_name, value| converted_value = if link_array?(value) convert_links(value) elsif value.is_a?(BasicObj) value.id elsif obj_array?(value) value.map(&:id) elsif value.is_a?(Time) || value.is_a?(Date) convert_time(value) elsif value.is_a?(Array) value.map(&:to_s) elsif value.is_a?(File) RailsConnector::CmsRestApi::BlobUploader.upload_file(value) else value.to_s end [attribute_name.to_s, converted_value] end ] end private def link_array?(value) value.is_a?(Array) && value.all? do |element| element.is_a?(Link) end end def obj_array?(value) value.is_a?(Array) && value.all? do |element| element.is_a?(BasicObj) end end def convert_links(links) links.map do |link| link.to_cms_api_linklist_params end end def convert_time(point_in_time) time_object = if point_in_time.instance_of?(Date) point_in_time.to_time else point_in_time.to_time.utc end time_object.strftime("%Y%m%d%H%M%S") end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
infopark_cloud_connector-7.1.0 | lib/rails_connector/cms_rest_api/attribute_serializer.rb |