Class: Mio::Model::MetadataDefinition

Inherits:
Mio::Model
  • Object
show all
Defined in:
lib/mio/model/metadata_definition.rb,
lib/mio/model/metadatadefinition/option.rb,
lib/mio/model/metadatadefinition/definition.rb

Defined Under Namespace

Classes: Definition, Option

Instance Attribute Summary

Attributes inherited from Mio::Model

#args, #client, #search

Instance Method Summary collapse

Methods inherited from Mio::Model

#configure, #create, field, #initialize, mappings, nested, #set_enable, set_resource, #set_start, #validate

Constructor Details

This class inherits a constructor from Mio::Model

Instance Method Details

#build_xmlObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mio/model/metadata_definition.rb', line 24

def build_xml
  xml_builder = Nokogiri::XML::Builder.new do |xml|
    xml.(name: @args.name ) {
      xml.searchable @args.searchable.to_s
      xml.editable @args.editable.to_s
      xml.required @args.required.to_s
      xml.children do |children|
        @args.definitions.each do |defs|
          definition = Mio::Model::MetadataDefinition::Definition.new @client, OpenStruct.new(defs)
          definition.build_xml children
        end
      end
    }
  end
  xml_builder.to_xml
end

#create_hashObject



19
20
21
22
# File 'lib/mio/model/metadata_definition.rb', line 19

def create_hash
  {name: @args.name,
   visibilityIds: @args.visibility}
end

#goObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mio/model/metadata_definition.rb', line 41

def go
  if @args.definitions.empty?
    raise Mio::Model::EmptyField, 'Field definitions to Mio::Model::MetadataDefinition must contain at least one definition'
  end

  @object = look_up
  unless @object
    @object = create
  else
    set_start :stop
  end
  definition_path = "#{self.class.resource_name}/#{@object['id']}/definition"

  @client.definition definition_path, build_xml

  set_enable
  return @object
end