Class: ArchivesSpaceDynamicEnumAttribute

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

Class Method Summary collapse

Class Method Details

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



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# 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(', ')}")

    # 11/26/18: added this check because many Selenium tests were failing here with a NoMethodError
    enum_source = JSONModel.init_args[:enum_source]
    if enum_source.respond_to?(:editable?) &&
       enum_source.editable?(enum_name)

      klass = self
    else
      klass = ArchivesSpaceReadOnlyDynamicEnumAttribute
    end

    validation_error(message, fragments, current_schema, klass, options[:record_errors])
  end
end