Method: RestfulObjects::PropertyDescription#initialize

Defined in:
lib/restful_objects/domain_model/types/property_description.rb

#initialize(id, domain_type, return_type, options) ⇒ PropertyDescription

Returns a new instance of PropertyDescription.



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

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" unless [: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