Class: RestfulObjects::ParameterDescription

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

Constant Summary

Constants included from LinkGenerator

LinkGenerator::HTTP_OK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LinkGenerator

#generate_rel, #generate_repr_type, #link_to, #ro_content_type_for_object, #ro_content_type_for_object_collection, #ro_content_type_for_property, #underscore_to_hyphen_string

Constructor Details

#initialize(id, definition, number) ⇒ ParameterDescription

Returns a new instance of ParameterDescription.



7
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/restful_objects/domain_model/types/parameter_description.rb', line 7

def initialize(id, definition, number)
  @id = id
  @name = id

  if definition.is_a?(Array)# [type, options]
    if [:string, :int, :decimal, :date, :blob].include?(definition.first) # scalar
      @kind_type = :scalar
      @type = definition.first
    elsif definition.first.is_a?(Class) # object type
      @kind_type = :object
      @type = definition.first.name
    elsif definition.first.is_a?(Strign) # object type
      @kind_type = :object
      @type = definition.first
    else
      raise "unssuported parameter definition type #{definition.class}"
    end
    options = definition.last
  elsif definition.is_a?(Symbol) # scalar type
    @kind_type = :scalar
    @type = definition
    raise "result type for scalar '#{@type}' unssuported" unless [:string, :int, :decimal, :date, :blob].include?(@type)
  elsif definition.is_a?(String)# object type
    @kind_type = :object
    @type = definition
  elsif definition.is_a?(Class)# object type
    @kind_type = :object
    @type = definition.to_s
  else
    raise "unssuported parameter definition type #{definition.class}"
  end

  options ||= {}
  @number = options[:number] || number
  @friendly_name = options[:friendly_name] || id
  @description = options[:description] || id
  @optional = options[:optional].nil? ? true : options[:optional]
  @max_length = options[:max_length]
  @pattern = options[:pattern]
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#friendly_nameObject

Returns the value of attribute friendly_name.



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

def id
  @id
end

#kind_typeObject (readonly)

Returns the value of attribute kind_type.



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

def kind_type
  @kind_type
end

#max_lengthObject

Returns the value of attribute max_length.



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

def max_length
  @max_length
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

#optionalObject

Returns the value of attribute optional.



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

def pattern
  @pattern
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#metadataObject



48
49
50
51
52
53
54
# File 'lib/restful_objects/domain_model/types/parameter_description.rb', line 48

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