Class: ArchivesSpaceDynamicEnumAttribute

Inherits:
JSON::Schema::TypeAttribute
  • Object
show all
Defined in:
common/archivesspace_json_schema.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) validate(current_schema, data, fragments, validator, options = {})



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'common/archivesspace_json_schema.rb', line 136

def self.validate(current_schema, data, fragments, validator, options = {})
  enum_name = current_schema.schema['dynamic_enum']

  if !JSONModel.init_args[:enum_source].valid?(enum_name, data)
    possible_values = JSONModel.init_args[:enum_source].values_for(enum_name)  
    message = ("The property '#{build_fragment(fragments)}' value #{data.inspect} " +
               "did not match one of the following configurable values: #{possible_values.join(', ')}")
   
    if JSONModel.init_args[:enum_source].editable?(enum_name)
      klass = self
    else
      klass = ArchivesSpaceReadOnlyDynamicEnumAttribute
    end
    
    validation_error(message, fragments, current_schema, klass, options[:record_errors])
  end
end