Sha256: 1f91b6f423a6b28bab6849c5e782ff84de60f45a7ed3b4a4c43dfef541060de5

Contents?: true

Size: 955 Bytes

Versions: 9

Compression:

Stored size: 955 Bytes

Contents

#
#  Resource model. Something like a DOM model for the api. 
#
module Restful
  module ApiModel
    class Map
      attr_accessor :values, :name, :type

      def initialize(name)
        self.name = name
        self.type = :hash
        self.values = []
      end

      def links
        self.values.select { |attribute| attribute.type == :link }
      end

      def simple_attributes
        self.values.select { |attribute| attribute.type == :simple_attribute }        
      end

      def collections
        self.values.select { |attribute| attribute.type == :collection }
      end

      # invoke serialization
      def serialize(type)
        serializer = Restful::Serializers::Base.serializer(type)
        serializer.serialize(self)
      end

      # invoke deserialization
      def deserialize_from(type)
        serializer = Restful::Serializers::Base.serializer(type)
        serializer.deserialize(self)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
benjaminkrause-restful-0.2.8 lib/restful/apimodel/map.rb
purzelrakete-restful-0.2.10 lib/restful/apimodel/map.rb
purzelrakete-restful-0.2.11 lib/restful/apimodel/map.rb
purzelrakete-restful-0.2.12 lib/restful/apimodel/map.rb
purzelrakete-restful-0.2.13 lib/restful/apimodel/map.rb
purzelrakete-restful-0.2.14 lib/restful/apimodel/map.rb
purzelrakete-restful-0.2.15 lib/restful/apimodel/map.rb
purzelrakete-restful-0.2.8 lib/restful/apimodel/map.rb
purzelrakete-restful-0.2.9 lib/restful/apimodel/map.rb