Class: Spectifly::Json::Association

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

Instance Attribute Summary

Attributes inherited from Base::Association

#relationship

Attributes inherited from Base::EntityNode

#attributes, #description, #example, #inherits_from, #name, #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

#to_hObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spectifly/json/association.rb', line 4

def to_h
  fields = {
    :type => type,
    :required => required?,
  }
  [:description, :example, :restrictions].each do |opt|
    value = self.send(opt)
    if value && !value.empty?
      fields[opt] = value
    end
  end
  { name.to_sym => fields}
end