Class: Mio::Model::MetadataDefinition::Definition
- Inherits:
-
Mio::Model
- Object
- Mio::Model
- Mio::Model::MetadataDefinition::Definition
show all
- Defined in:
- lib/mio/model/metadatadefinition/definition.rb
Instance Attribute Summary
Attributes inherited from Mio::Model
#args, #client, #search
Instance Method Summary
collapse
Methods inherited from Mio::Model
#configure, #create, field, #go, #initialize, mappings, nested, #set_enable, set_resource, #set_start
Constructor Details
This class inherits a constructor from Mio::Model
Instance Method Details
#boolean_option_check ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/mio/model/metadatadefinition/definition.rb', line 111
def boolean_option_check
if @args.type == 'boolean'
@args.options.each do |option|
unless option[:name] =~ /^(true|false)$/
raise Mio::Model::DataValueError, "Boolean option name must be true|false"
end
unless option[:value] =~ /^(true|false)$/
raise Mio::Model::DataValueError, "Boolean option value must be true|false"
end
if option[:name] == 'true' && option[:value] != 'true'
raise Mio::Model::DataValueError, "true option name must have true option value"
end
if option[:name] == 'false' && option[:value] != 'false'
raise Mio::Model::DataValueError, "false option name must have false option value"
end
end
end
end
|
#build_xml(children, type = nil) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/mio/model/metadatadefinition/definition.rb', line 57
def build_xml children, type=nil
if type.nil?
type = @args.type
end
children.send(type+'_', name: @args.name, display_name: @args.displayName) do |child|
unless @args.multiplicity.nil?
child.parent['multiplicity'] = @args.multiplicity
end
child.searchable @args.searchable.to_s
child.editable @args.editable.to_s
child.required @args.required
child.isVisible @args.isVisible
child.description @args.description
unless @args.maxLength.equal?(-1)
child.send("max-length", @args.maxLength )
end
if @args.validation_handler.nil? || @args.validation_handler == ''
child.validation handler: validation_handler_by_type(type)
else
child.validation handler: validation_handler
end
child.send("form-type", @args.formType)
if !@args.options.nil? && @args.options.length > 0
child.children do |children|
@args.options.each do |option|
option_model = Mio::Model::MetadataDefinition::Option.new @client, OpenStruct.new(option)
option_model.build_xml children
end
end
end
if !@args.children.nil? && @args.children.length > 0
child.children do |children|
@args.children.each do |childDef|
definition = Mio::Model::MetadataDefinition::Definition.new @client, OpenStruct.new(childDef)
definition.build_xml children, childDef[:type]
end
end
end
end
end
|
#create_hash ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/mio/model/metadatadefinition/definition.rb', line 24
def create_hash
{name: @args.name,
displayName: @args.displayName,
type: @args.type,
description: @args.description,
searchable: @args.searchable,
editable: @args.editable,
required: @args.required,
formType: @args.formType,
maxLength: @args.maxLength,
validationHandler: @args.validationHandler,
options: @args.options,
children: @args.children,
multiplicity: @args.multiplicity,
isVisible: @args.isVisible
}
end
|
#multiple_identical_options(key) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/mio/model/metadatadefinition/definition.rb', line 98
def multiple_identical_options key
hash_count = @args.options.each_with_object(Hash.new(0)) { |option, count| count[option[key.to_sym]] += 1 }
error_msg = ''
hash_count.each do |key, count|
if count > 1
error_msg += error_msg == '' ? "#{key} occurs #{count} times" : ", #{key} occurs #{count} times"
end
end
unless error_msg == ''
raise Mio::Model::DataValueError, "Multiple identical options not allowed [" + error_msg + "]"
end
end
|
#validate ⇒ Object
Also known as:
valid?
130
131
132
133
134
135
136
|
# File 'lib/mio/model/metadatadefinition/definition.rb', line 130
def validate
super
multiple_identical_options 'name'
multiple_identical_options 'value'
boolean_option_check
true
end
|
#validation_handler_by_type(type) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/mio/model/metadatadefinition/definition.rb', line 42
def validation_handler_by_type type
case type
when 'text'
'tv.nativ.mio.metadata.variable.def.validation.MaxLengthValidationHandler'
when 'image'
'tv.nativ.mio.metadata.resource.def.MioFileVariable.FileValidationHandler'
when 'string'
'tv.nativ.mio.metadata.variable.def.validation.MaxLengthValidationHandler'
when 'url'
'tv.nativ.mio.metadata.resource.def.MioURLVariable$URLValidationHandler'
else
''
end
end
|