Sha256: 973a6437773a4637a9b2bc042afa75b573f564f92b5820ff273715df5f5e3a75

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

module RestfulObjects
  class CollectionDescription
    include LinkGenerator
    attr_reader :id, :type, :read_only
    attr_accessor :friendly_name, :description, :plural_form, :member_order, :disabled_reason

    def initialize(id, type, domain_type, options = {})
      @id = id
      @type = type
      @domain_type = domain_type
      @read_only = options[:read_only].nil? ? false : options[:read_only]
      @disabled_reason = options[:disabled_reason] || 'read only collection' if read_only
      @friendly_name = options[:friendly_name] || id
      @description = options[:description] || id
      @plural_form = options[:plural_form]
      @member_order = options[:member_order]
    end

    def get_representation
      representation = {
        'id' => id,
        'memberOrder' => member_order,
        'links' => [
          link_to(:self, "/domain-types/#{@domain_type}/collections/#{@id}", :collection_description),
          link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
          link_to(:return_type, "/domain-types/list", :domain_type),
          link_to(:element_type, "/domain-types/#{@type}", :domain_type)
        ],
        'extensions' => metadata
      }

      representation['friendlyName'] = friendly_name if friendly_name
      representation['description'] = description if description

      representation.to_json
    end

    def metadata
      { 'friendlyName' => friendly_name,
        'description' => description,
        'returnType' => 'list',
        'elementType' => type,
        'memberOrder' => member_order,
        'pluralForm' => plural_form }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
restful_objects-0.0.7 lib/restful_objects/domain_model/types/collection_description.rb
restful_objects-0.0.6 lib/restful_objects/domain_model/types/collection_description.rb
restful_objects-0.0.5 lib/restful_objects/collection_description.rb
restful_objects-0.0.4 lib/restful_objects/collection_description.rb
restful_objects-0.0.3 lib/restful_objects/collection_description.rb