Class: Spectifly::Base::Field
Instance Attribute Summary
Attributes inherited from EntityNode
#attributes, #description, #example, #inherits_from, #name, #restrictions, #validations
Instance Method Summary
collapse
Methods inherited from EntityNode
#display_type, #initialize, #required?, #unique?
Instance Method Details
6
7
8
9
10
11
12
|
# File 'lib/spectifly/base/field.rb', line 6
def
super
@multiple = @attributes.delete('Multiple') == true
if @tokens.include?('?') && @type && @type != 'Boolean'
raise ArgumentError, "Boolean field has conflicting type"
end
end
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/spectifly/base/field.rb', line 14
def
super
['Minimum Value', 'Maximum Value', 'Valid Values'].each do |restriction|
if @attributes[restriction]
token = Spectifly::Support.tokenize(restriction)
@restrictions[token] = @attributes.delete(restriction)
end
end
@validations.each do |validation|
if validation =~ /^Must match regex "(.*)"$/
@validations.delete(validation)
@restrictions['regex'] = /#{$1}/
end
end
@restrictions
end
|
#multiple? ⇒ Boolean
37
38
39
|
# File 'lib/spectifly/base/field.rb', line 37
def multiple?
@multiple
end
|
#type ⇒ Object
31
32
33
34
35
|
# File 'lib/spectifly/base/field.rb', line 31
def type
type = super
type = 'boolean' if @tokens.include?('?')
type || 'string'
end
|