Sha256: afe6b85afcc9aec531893db6deb8686d5a0645d6555f99e0f9318a2991edaba3

Contents?: true

Size: 990 Bytes

Versions: 5

Compression:

Stored size: 990 Bytes

Contents

module Spectifly
  module Xsd
    class Association < Spectifly::Base::Association
      def name
        Spectifly::Support.camelize(@field_name).gsub(/\W/, '')
      end

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

      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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spectifly-0.0.5 lib/spectifly/xsd/association.rb
spectifly-0.0.4 lib/spectifly/xsd/association.rb
spectifly-0.0.3 lib/spectifly/xsd/association.rb
spectifly-0.0.2 lib/spectifly/xsd/association.rb
spectifly-0.0.1 lib/spectifly/xsd/association.rb