Class: RestfulObjects::ParameterDescription

Inherits:
Object
  • Object
show all
Includes:
LinkGenerator
Defined in:
lib/restful_objects/domain_model/types/parameter_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, definition, number) ⇒ ParameterDescription



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

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" if not [: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.



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

def description
  @description
end

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#friendly_nameObject

Returns the value of attribute friendly_name.



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

def friendly_name
  @friendly_name
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#kind_typeObject (readonly)

Returns the value of attribute kind_type.



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

def kind_type
  @kind_type
end

#max_lengthObject

Returns the value of attribute max_length.



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

def max_length
  @max_length
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

#optionalObject

Returns the value of attribute optional.



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

def optional
  @optional
end

#patternObject

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#metadataObject



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

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