Class: RestfulObjects::PropertyDescription

Inherits:
Object
  • Object
show all
Includes:
LinkGenerator
Defined in:
lib/restful_objects/domain_model/types/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

Returns a new instance of PropertyDescription.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/restful_objects/domain_model/types/property_description.rb', line 8

def initialize(id, domain_type, return_type, options)
  if return_type.is_a?(Hash)
    raise "hash with :object key expected for property reference" unless return_type.has_key?(:object)
  else
    raise "property type #{return_type} usupported" if not [:string, :int, :bool, :decimal, :date, :blob].include?(return_type)
  end

  @id              = id
  @domain_type     = domain_type
  if return_type.is_a?(Hash)
    @return_type  = return_type[:object]
    @is_reference = true
  else
    @return_type  = return_type
    @is_reference = false
  end
  @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/domain_model/types/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/domain_model/types/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/domain_model/types/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/domain_model/types/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/domain_model/types/property_description.rb', line 5

def id
  @id
end

#is_referenceObject

Returns the value of attribute is_reference.



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

def is_reference
  @is_reference
end

#max_lengthObject

Returns the value of attribute max_length.



5
6
7
# File 'lib/restful_objects/domain_model/types/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/domain_model/types/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/domain_model/types/property_description.rb', line 5

def optional
  @optional
end

#patternObject

Returns the value of attribute pattern.



5
6
7
# File 'lib/restful_objects/domain_model/types/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/domain_model/types/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/domain_model/types/property_description.rb', line 5

def return_type
  @return_type
end

Instance Method Details

#formatObject



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

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

#get_representationObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/restful_objects/domain_model/types/property_description.rb', line 34

def get_representation
  {
    'id'           => @id,
    'friendlyName' => friendly_name || '',
    'description'  => description || '',
    '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' => {}
  }.to_json
end

#get_value_as_jsonObject



69
70
71
72
73
# File 'lib/restful_objects/domain_model/types/property_description.rb', line 69

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

#metadataObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/restful_objects/domain_model/types/property_description.rb', line 50

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