Class: RestfulObjects::PropertyDescription
- Inherits:
-
Object
- Object
- RestfulObjects::PropertyDescription
- Includes:
- LinkGenerator
- Defined in:
- lib/restful_objects/domain_model/types/property_description.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#disabled_reason ⇒ Object
Returns the value of attribute disabled_reason.
-
#domain_type ⇒ Object
Returns the value of attribute domain_type.
-
#friendly_name ⇒ Object
Returns the value of attribute friendly_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_reference ⇒ Object
Returns the value of attribute is_reference.
-
#max_length ⇒ Object
Returns the value of attribute max_length.
-
#member_order ⇒ Object
Returns the value of attribute member_order.
-
#optional ⇒ Object
Returns the value of attribute optional.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#read_only ⇒ Object
Returns the value of attribute read_only.
-
#return_type ⇒ Object
Returns the value of attribute return_type.
Instance Method Summary collapse
- #format ⇒ Object
- #get_representation ⇒ Object
- #get_value_as_json ⇒ Object
-
#initialize(id, domain_type, return_type, options) ⇒ PropertyDescription
constructor
A new instance of PropertyDescription.
- #metadata ⇒ Object
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, ) 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 = [:friendly_name] || id @description = [:description] || id @optional = [:optional].nil? ? true : [:optional] @read_only = [:read_only].nil? ? false : [:read_only] @member_order = [:member_order] || 1 @max_length = [:max_length] @disabled_reason = [:disabled_reason] || 'read-only property' if read_only @pattern = [:pattern] end |
Instance Attribute Details
#description ⇒ Object
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_reason ⇒ Object
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_type ⇒ Object
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_name ⇒ Object
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 |
#id ⇒ Object
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_reference ⇒ Object
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_length ⇒ Object
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_order ⇒ Object
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 |
#optional ⇒ Object
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 |
#pattern ⇒ Object
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_only ⇒ Object
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_type ⇒ Object
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
#format ⇒ Object
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_representation ⇒ Object
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_json ⇒ Object
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 |
#metadata ⇒ Object
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 |