Class: Spectifly::Xsd::Association

Inherits:
Base::Association show all
Defined in:
lib/spectifly/xsd/association.rb

Instance Attribute Summary

Attributes inherited from Base::Association

#relationship

Attributes inherited from Base::EntityNode

#attributes, #description, #example, #inherits_from, #restrictions, #validations

Instance Method Summary collapse

Methods inherited from Base::Association

#initialize, #multiple?

Methods inherited from Base::EntityNode

#display_type, #extract_attributes, #extract_restrictions, #initialize, #required?, #type, #unique?

Constructor Details

This class inherits a constructor from Spectifly::Base::Association

Instance Method Details

#embedded_blockObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/spectifly/xsd/association.rb', line 23

def embedded_block
  if description || example
    Proc.new { |el|
      if description || example
        el.xs :annotation do |ann|
          ann.xs :documentation, description if description
          ann.xs :documentation, "Example: #{example}" if example
        end
      end
    }
  end
end

#nameObject



4
5
6
# File 'lib/spectifly/xsd/association.rb', line 4

def name
  Spectifly::Support.camelize(@field_name).gsub(/\W/, '')
end

#to_xsd(builder = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/spectifly/xsd/association.rb', line 8

def to_xsd(builder = nil)
  builder ||= ::Builder::XmlMarkup.new(:indent => 2)
  if relationship =~ /^belongs_to(_many)?/
    attributes['name'] = "#{name}Id"
    attributes['type'] = "xs:string"
  else
    attributes['name'] = name
    attributes['type'] = "#{Spectifly::Support.lower_camelize(type)}Type"
  end
  attributes['minOccurs'] = '0' unless required?
  attributes['maxOccurs'] = 'unbounded' if multiple?
  block = embedded_block
  builder.xs :element, attributes, &block
end