Class: Ml::ModelVersion

Inherits:
ApplicationRecord show all
Includes:
CacheMarkdownField, Presentable, SemanticVersionable, Sortable
Defined in:
app/models/ml/model_version.rb

Constant Summary

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from CacheMarkdownField

#skip_markdown_cache_validation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CacheMarkdownField

#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #store_mentions?, #store_mentions_after_commit?, #updated_cached_html_for

Methods included from Presentable

#present

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, sharding_keys, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.by_project_id_and_id(project_id, id) ⇒ Object



61
62
63
# File 'app/models/ml/model_version.rb', line 61

def by_project_id_and_id(project_id, id)
  find_by(project_id: project_id, id: id)
end

.by_project_id_name_and_version(project_id, name, version) ⇒ Object



65
66
67
# File 'app/models/ml/model_version.rb', line 65

def by_project_id_name_and_version(project_id, name, version)
  joins(:model).find_by(model: { name: name, project_id: project_id }, project_id: project_id, version: version)
end

.find_or_create!(model, version, package, description) ⇒ Object



56
57
58
59
# File 'app/models/ml/model_version.rb', line 56

def find_or_create!(model, version, package, description)
  create_with(package: package, description: description)
    .find_or_create_by!(project: model.project, model: model, version: version)
end

Instance Method Details

#add_metadata(metadata_key_value) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/ml/model_version.rb', line 43

def ()
  return unless .present?

  .each do |entry|
    .create!(
      project_id: project_id,
      name: entry[:key],
      value: entry[:value]
    )
  end
end

#version=(value) ⇒ Object



70
71
72
73
# File 'app/models/ml/model_version.rb', line 70

def version=(value)
  self.semver = value
  super(value)
end