Class: RestfulObjects::CollectionDescription

Inherits:
Object
  • Object
show all
Includes:
LinkGenerator
Defined in:
lib/restful_objects/domain_model/types/collection_description.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LinkGenerator

#generate_rel, #generate_repr_type, #link_to, #underscore_to_hyphen_string

Constructor Details

#initialize(id, type, domain_type, options = {}) ⇒ CollectionDescription

Returns a new instance of CollectionDescription.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 7

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

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 5

def description
  @description
end

#disabled_reasonObject

Returns the value of attribute disabled_reason.



5
6
7
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 5

def disabled_reason
  @disabled_reason
end

#friendly_nameObject

Returns the value of attribute friendly_name.



5
6
7
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 5

def friendly_name
  @friendly_name
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 4

def id
  @id
end

#member_orderObject

Returns the value of attribute member_order.



5
6
7
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 5

def member_order
  @member_order
end

#plural_formObject

Returns the value of attribute plural_form.



5
6
7
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 5

def plural_form
  @plural_form
end

#read_onlyObject (readonly)

Returns the value of attribute read_only.



4
5
6
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 4

def read_only
  @read_only
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 4

def type
  @type
end

Instance Method Details

#get_representationObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 19

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' => 
  }

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

  representation.to_json
end

#metadataObject



38
39
40
41
42
43
44
45
# File 'lib/restful_objects/domain_model/types/collection_description.rb', line 38

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