class Mio::Model::MetadataDefinition::Definition
Public Instance Methods
boolean_option_check()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
Calls superclass method
Mio::Model#validate
# 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
Also aliased as: valid?
validation_handler_by_type(type)
click to toggle source
# 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