Class: RestfulObjects::PropertyDescription

Inherits:
Object
  • Object
show all
Includes:
LinkGenerator
Defined in:
lib/restful_objects/property_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, domain_type, return_type, options) ⇒ PropertyDescription



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/restful_objects/property_description.rb', line 8

def initialize(id, domain_type, return_type, options)
  raise "property type #{return_type} usupported" if not [:string, :int, :decimal, :date, :blob].include?(return_type)

  @id = id
  @domain_type = domain_type
  @return_type = return_type
  @friendly_name = options[:friendly_name] || id
  @description = options[:description] || id
  @optional = options[:optional].nil? ? true : options[:optional]
  @read_only = options[:read_only].nil? ? false : options[:read_only]
  @member_order = options[:member_order] || 1
  @max_length = options[:max_length]
  @disabled_reason = options[:disabled_reason] || 'read-only property' if read_only
  @pattern = options[:pattern]
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def description
  @description
end

#disabled_reasonObject

Returns the value of attribute disabled_reason.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def disabled_reason
  @disabled_reason
end

#domain_typeObject

Returns the value of attribute domain_type.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def domain_type
  @domain_type
end

#friendly_nameObject

Returns the value of attribute friendly_name.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def friendly_name
  @friendly_name
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def id
  @id
end

#max_lengthObject

Returns the value of attribute max_length.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def max_length
  @max_length
end

#member_orderObject

Returns the value of attribute member_order.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def member_order
  @member_order
end

#optionalObject

Returns the value of attribute optional.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def optional
  @optional
end

#patternObject

Returns the value of attribute pattern.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def pattern
  @pattern
end

#read_onlyObject

Returns the value of attribute read_only.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def read_only
  @read_only
end

#return_typeObject

Returns the value of attribute return_type.



5
6
7
# File 'lib/restful_objects/property_description.rb', line 5

def return_type
  @return_type
end

Instance Method Details

#formatObject



55
56
57
58
59
60
# File 'lib/restful_objects/property_description.rb', line 55

def format
  case return_type
    when :string
      'string'
  end
end

#get_representationObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/restful_objects/property_description.rb', line 24

def get_representation
  representation = {
    'id' => @id,
    'optional' => optional,
    'memberOrder' => @member_order,
    'links' => [
      link_to(:self, "/domain-types/#{@domain_type}/properties/#{@id}", :property_description),
      link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
      link_to(:return_type, "/domain-types/#{@return_type}", :domain_type)
    ],
    'extensions' => {}
  }

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

  representation.to_json
end

#get_value_as_jsonObject



62
63
64
65
66
# File 'lib/restful_objects/property_description.rb', line 62

def get_value_as_json
  { 'id' =>
    { 'value' => '' }
  }.to_json
end

#metadataObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/restful_objects/property_description.rb', line 43

def 
  result = { 'friendlyName' => friendly_name,
             'description' => description,
             'returnType' => return_type,
             'format' => format,
             'optional' => optional,
             'memberOrder' => member_order }
  result['maxLength'] = max_length if max_length
  result['pattern'] = pattern if pattern
  result
end