Class: OnboardingProgress
Constant Summary
collapse
- ACTIONS =
[
:git_pull,
:git_write,
:merge_request_created,
:pipeline_created,
:user_added,
:trial_started,
:subscription_created,
:required_mr_approvals_enabled,
:code_owners_enabled,
:scoped_label_created,
:security_scan_enabled,
:issue_created,
:issue_auto_closed,
:repository_imported,
:repository_mirrored,
:secure_dependency_scanning_run,
:secure_container_scanning_run,
:secure_dast_run,
:secure_secret_detection_run,
:secure_coverage_fuzzing_run,
:secure_api_fuzzing_run,
:secure_cluster_image_scanning_run,
:license_scanning_run
].freeze
ApplicationRecord::MAX_PLUCK
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, 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
#serializable_hash
Class Method Details
.column_name(action) ⇒ Object
92
93
94
|
# File 'app/models/onboarding_progress.rb', line 92
def column_name(action)
:"#{action}_at"
end
|
.completed?(namespace, action) ⇒ Boolean
78
79
80
81
82
83
|
# File 'app/models/onboarding_progress.rb', line 78
def completed?(namespace, action)
return unless root_namespace?(namespace) && ACTIONS.include?(action)
action_column = column_name(action)
where(namespace: namespace).where.not(action_column => nil).exists?
end
|
.not_completed?(namespace_id, action) ⇒ Boolean
85
86
87
88
89
90
|
# File 'app/models/onboarding_progress.rb', line 85
def not_completed?(namespace_id, action)
return unless ACTIONS.include?(action)
action_column = column_name(action)
where(namespace_id: namespace_id).where(action_column => nil).exists?
end
|
.onboard(namespace) ⇒ Object
53
54
55
56
57
|
# File 'app/models/onboarding_progress.rb', line 53
def onboard(namespace)
return unless root_namespace?(namespace)
create(namespace: namespace)
end
|
.onboarding?(namespace) ⇒ Boolean
59
60
61
|
# File 'app/models/onboarding_progress.rb', line 59
def onboarding?(namespace)
where(namespace: namespace).any?
end
|
.register(namespace, actions) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/models/onboarding_progress.rb', line 63
def register(namespace, actions)
actions = Array(actions)
return unless root_namespace?(namespace) && actions.difference(ACTIONS).empty?
onboarding_progress = find_by(namespace: namespace)
return unless onboarding_progress
now = Time.current
nil_actions = actions.select { |action| onboarding_progress[column_name(action)].nil? }
return if nil_actions.empty?
updates = nil_actions.inject({}) { |sum, action| sum.merge!({ column_name(action) => now }) }
onboarding_progress.update!(updates)
end
|
Instance Method Details
#number_of_completed_actions ⇒ Object
103
104
105
|
# File 'app/models/onboarding_progress.rb', line 103
def number_of_completed_actions
attributes.(*ACTIONS.map { |action| self.class.column_name(action).to_s }).compact!.size
end
|