class ZmLdifExport::Attribute

Constants

WHITE_LIST

Attributes

name[R]
type[R]

Public Class Methods

new(xml_attr) click to toggle source
# File lib/zmldifexport.rb, line 138
def initialize(xml_attr)
  @name = xml_attr.attributes['name'].value
  @singular = attr_is_singular?(xml_attr)
  @immutable = attr_is_immutable?(xml_attr)
  @type = xml_attr.attributes['type'].value
end

Public Instance Methods

boolean?() click to toggle source
# File lib/zmldifexport.rb, line 169
def boolean?
  type == "boolean"
end
command_multiline(attr_name:,value:) click to toggle source
# File lib/zmldifexport.rb, line 193
def command_multiline(attr_name:,value:)
  final_wrapper = attr_name == 'zimbraMailSieveScript' ? "'" : '"'
  original_wrapper = attr_name == 'zimbraMailSieveScript' ? '"' : "'"
  line = "#{attr_name} #{final_wrapper}"
  line << value.join('').to_s.gsub(final_wrapper, original_wrapper).split(/\n/).join("\n")
  line << "#{final_wrapper} \\\n"
  line
end
enum?() click to toggle source
# File lib/zmldifexport.rb, line 165
def enum?
  type == 'enum'
end
immutable?() click to toggle source
# File lib/zmldifexport.rb, line 149
def immutable?
  @immutable
end
multiline?() click to toggle source
# File lib/zmldifexport.rb, line 153
def multiline?
  name == 'zimbraPrefMailSignatureHTML' || name == 'zimbraMailSieveScript' || name == 'zimbraPrefOutOfOfficeReply' || name == 'zimbraPrefOutOfOfficeExternalReply'
end
number?() click to toggle source
# File lib/zmldifexport.rb, line 161
def number?
  type == 'integer' || type == 'long'
end
singular?() click to toggle source
# File lib/zmldifexport.rb, line 145
def singular?
  @singular
end
text?() click to toggle source
# File lib/zmldifexport.rb, line 157
def text?
  type == 'string' || type == 'duration' || name == 'zimbraACE' || type == 'regex'
end
to_zmprov(value, plus = false) click to toggle source
# File lib/zmldifexport.rb, line 173
def to_zmprov(value, plus = false)
  if multiline?
    command_multiline attr_name: name, value: value
  elsif singular?
    return " \\\n#{name} '#{value.join('').to_s}'" if text?
    return " \\\n#{name} #{value.join('').to_i}" if number?
    return " \\\n#{name} #{value.join('').to_s}"
  else
    line = " \\\n#{name} "
    value = text? ? value.map {|v| "'#{v}'"} : value
    if plus
      line << value.join(" +#{name} ")
    else
      line << value.join(" \\\n#{name} ")
    end
      
    line
  end
end

Private Instance Methods

attr_is_immutable?(attr) click to toggle source
# File lib/zmldifexport.rb, line 210
def attr_is_immutable?(attr)
  return false if WHITE_LIST.include?(name)
  return false if attr.attributes['immutable'].nil? 
  attr.attributes['immutable'].value == '1'
end
attr_is_singular?(attr) click to toggle source
# File lib/zmldifexport.rb, line 204
def attr_is_singular?(attr)
  return false if attr.attributes['cardinality'].nil?
  return true if attr.attributes['type'] == 'astring'
  attr.attributes['cardinality'].value == 'single'
end