Class: Packages::Dependency
Constant Summary
collapse
- NAME_VERSION_PATTERN_TUPLE_MATCHING =
'(name, version_pattern) = (?, ?)'
- MAX_STRING_LENGTH =
255
- MAX_CHUNKED_QUERIES_COUNT =
10
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary
collapse
Instance Method Summary
collapse
===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.for_package_project_id_names_and_version_patterns(project_id, names_and_version_patterns = {}, chunk_size = 50, max_rows_limit = 200) ⇒ Object
38
39
40
41
42
43
44
|
# File 'app/models/packages/dependency.rb', line 38
def self.for_package_project_id_names_and_version_patterns(project_id, names_and_version_patterns = {}, chunk_size = 50, max_rows_limit = 200)
ids = ids_for_package_project_id_names_and_version_patterns(project_id, names_and_version_patterns, chunk_size, max_rows_limit)
return none if ids.empty?
id_in(ids)
end
|
.ids_for_package_project_id_names_and_version_patterns(project_id, names_and_version_patterns = {}, chunk_size = 50, max_rows_limit = 200) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/models/packages/dependency.rb', line 18
def self.ids_for_package_project_id_names_and_version_patterns(project_id, names_and_version_patterns = {}, chunk_size = 50, max_rows_limit = 200)
names_and_version_patterns.reject! { |key, value| key.size > MAX_STRING_LENGTH || value.size > MAX_STRING_LENGTH }
raise ArgumentError, 'Too many names_and_version_patterns' if names_and_version_patterns.size > MAX_CHUNKED_QUERIES_COUNT * chunk_size
matched_ids = []
names_and_version_patterns.each_slice(chunk_size) do |tuples|
where_statement = Array.new(tuples.size, NAME_VERSION_PATTERN_TUPLE_MATCHING)
.join(' OR ')
ids = where(where_statement, *tuples.flatten)
.where(project_id: project_id)
.limit(max_rows_limit + 1)
.pluck(:id)
matched_ids.concat(ids)
raise ArgumentError, 'Too many Dependencies selected' if matched_ids.size > max_rows_limit
end
matched_ids
end
|
.pluck_ids_and_names ⇒ Object
46
47
48
|
# File 'app/models/packages/dependency.rb', line 46
def self.pluck_ids_and_names
pluck(:id, :name)
end
|
Instance Method Details
#orphaned? ⇒ Boolean
55
56
57
|
# File 'app/models/packages/dependency.rb', line 55
def orphaned?
self.dependency_links.empty?
end
|