class PIM::DataModelManager::AttributeManager

Public Class Methods

new(data_model, name = nil) click to toggle source
# File data-model-manager.rb, line 205
def initialize data_model, name = nil
  super data_model
  @name = name
end

Public Instance Methods

[](name) click to toggle source
# File data-model-manager.rb, line 210
def [] name
  AttributeManager.new data_model, name
end
create(name, type = nil, params = nil) click to toggle source
# File data-model-manager.rb, line 214
def create name, type = nil, params = nil
  attribute = data_model.module_attributes[name]
  if (attribute && attribute.modification_status != :DELETED)
    PIM.log_warn("Could not create Attribute '#{name}' because it already exists in module '#{data_model.name}'")
  else
    model_defined = attribute ? attribute.model_defined : false
    attribute = data_model.attribute name, type
    attribute.model_defined = model_defined
    attribute.modification_status = :CREATED
    attribute.merge_params(params) if params
  end
  attribute
end
delete() click to toggle source
# File data-model-manager.rb, line 248
def delete
  attribute = data_model.module_attributes[name]
  if (attribute)
    attribute.modification_status = :DELETED
  else
    PIM.log_warn("Could not delete attribute '#{name}' because it did not exist in module '#{data_model.name}'")
  end
  attribute
end
update(type = nil, params = nil) click to toggle source
# File data-model-manager.rb, line 228
def update type = nil, params = nil
  attribute = data_model.module_attributes[name]
  if (attribute)
    if (type && attribute.parent != type)
      attribute.clear_params
      if type.is_a? PIM::AttributeTemplate
        attribute.parent = type.base_class
        attribute.merge_params type.params
      else
        attribute.parent = type
      end
    end
    attribute.merge_params(params) if params
    attribute.modification_status = :UPDATED
  else
    PIM.log_warn("Could not update attribute '#{name}' because it did not exist in module '#{data_model.name}'")
  end
  attribute
end