Class: Ddr::Batch::BatchObjectAttribute

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ddr/batch/batch_object_attribute.rb

Constant Summary collapse

OPERATION_ADD =

Add the provided value to the attribute

"ADD"
OPERATION_DELETE =

Delete the provided value from the attribute

"DELETE"
OPERATION_CLEAR =

Clear all values from the attribute

"CLEAR"
OPERATION_CLEAR_ALL =

Clear all attributes in the datastream

"CLEAR_ALL"
OPERATIONS =
[ OPERATION_ADD, OPERATION_DELETE, OPERATION_CLEAR, OPERATION_CLEAR_ALL ]
VALUE_TYPE_STRING =
"STRING"
VALUE_TYPES =
[ VALUE_TYPE_STRING ]

Instance Method Summary collapse

Instance Method Details

#attribute_name_valid?Boolean

Returns:

  • (Boolean)

61
62
63
64
65
66
67
68
# File 'app/models/ddr/batch/batch_object_attribute.rb', line 61

def attribute_name_valid?
  case datastream
    when Ddr::Models::Metadata::ADMIN_METADATA
      batch_object.model.constantize.properties.include?(name)
    when Ddr::Models::Metadata::DESC_METADATA
      Ddr::Models::DescriptiveMetadata.unqualified_names.include?(name.to_sym)
  end
end

#datastream_typeObject


53
54
55
# File 'app/models/ddr/batch/batch_object_attribute.rb', line 53

def datastream_type
  batch_object.model.constantize.ds_specs[datastream][:type] rescue nil
end

#datastream_valid?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'app/models/ddr/batch/batch_object_attribute.rb', line 57

def datastream_valid?
    [ Ddr::Models::Metadata::ADMIN_METADATA, Ddr::Models::Metadata::DESC_METADATA ].include?(datastream)
end

#operation_requires_name?Boolean

Returns:

  • (Boolean)

37
38
39
# File 'app/models/ddr/batch/batch_object_attribute.rb', line 37

def operation_requires_name?
  [ OPERATION_ADD, OPERATION_DELETE, OPERATION_CLEAR ].include? operation
end

#operation_requires_value?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'app/models/ddr/batch/batch_object_attribute.rb', line 41

def operation_requires_value?
  [ OPERATION_ADD, OPERATION_DELETE ].include? operation
end

#valid_datastream_and_attribute_nameObject


45
46
47
48
49
50
51
# File 'app/models/ddr/batch/batch_object_attribute.rb', line 45

def valid_datastream_and_attribute_name
  if datastream_valid?
    errors.add(:name, "is not valid") unless attribute_name_valid?
  else
    errors.add(:datastream, "is not valid")
  end
end

#valid_datastream_operationObject


29
30
31
32
33
34
35
# File 'app/models/ddr/batch/batch_object_attribute.rb', line 29

def valid_datastream_operation
  if operation == OPERATION_CLEAR_ALL
    unless datastream == Ddr::Models::Metadata::DESC_METADATA
      errors.add(:operation, "Operation #{operation} is not valid for #{datastream}")
    end
  end
end