Sha256: 62cc0a5bff7f7e4379ba817fdfdb24ce0ac73580a1da8bb5874565a6b901414e
Contents?: true
Size: 1.36 KB
Versions: 10
Compression:
Stored size: 1.36 KB
Contents
# # Converts an APIModel to and from a given format. # module Restful module Serializers class Base cattr_accessor :serializers def serialize(resource, options = {}) # implement me. raise NotImplementedError.new end def deserialize(resource, options = {}) # implement me. raise NotImplementedError.new end # # Grabs a serializer, given... # # .serialize(:xml, Resource.new(:animal => "cow")) # def self.serializer(type) serializers[type].new end def self.serializer_name(key) self.serializers ||= {} self.serializers[key] = self end def formatted_value(value) return value unless value.respond_to?(:value) return nil if value.value.blank? && value.extended_type != :false_class case value.extended_type when :datetime value.value.xmlschema when :time value.value.xmlschema when :date value.value.to_s(:db) else value.value end end protected def transform_link_name(name) name.to_s.gsub /_id$/, "-restful-url" end def revert_link_name(name) name.to_s.gsub /-restful-url$/, "_id" end end end end
Version data entries
10 entries across 10 versions & 2 rubygems