Class: RestfulObjects::ParameterDescription
- Inherits:
-
Object
- Object
- RestfulObjects::ParameterDescription
- Includes:
- LinkGenerator
- Defined in:
- lib/restful_objects/domain_model/types/parameter_description.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#format ⇒ Object
Returns the value of attribute format.
-
#friendly_name ⇒ Object
Returns the value of attribute friendly_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind_type ⇒ Object
readonly
Returns the value of attribute kind_type.
-
#max_length ⇒ Object
Returns the value of attribute max_length.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#optional ⇒ Object
Returns the value of attribute optional.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(id, definition, number) ⇒ ParameterDescription
constructor
A new instance of ParameterDescription.
- #metadata ⇒ Object
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 = 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 ||= {} @number = [:number] || number @friendly_name = [:friendly_name] || id @description = [:description] || id @optional = [:optional].nil? ? true : [:optional] @max_length = [:max_length] @pattern = [:pattern] end |
Instance Attribute Details
#description ⇒ Object
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 |
#format ⇒ Object
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_name ⇒ Object
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 |
#id ⇒ Object (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_type ⇒ Object (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_length ⇒ Object
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 |
#name ⇒ Object (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 |
#number ⇒ Object (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 |
#optional ⇒ Object
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 |
#pattern ⇒ Object
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 |
#type ⇒ Object (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
#metadata ⇒ Object
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 |