Class: Operations::FeatureFlag

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue, AtomicInternalId, IidRoutes, Limitable, Referable
Defined in:
app/models/operations/feature_flag.rb

Constant Summary

Constants included from Limitable

Limitable::GLOBAL_SCOPE

Constants included from AtomicInternalId

AtomicInternalId::MissingValueError

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Referable

#referable_inspect, #reference_link_text, #to_reference_base

Methods included from Limitable

#exceeds_limits?

Methods included from IidRoutes

#to_param

Methods included from AtomicInternalId

group_init, #internal_id_read_scope, #internal_id_scope_attrs, #internal_id_scope_usage, namespace_init, project_init, scope_attrs, scope_usage

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

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

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.for_unleash_client(project, environment) ⇒ Object



58
59
60
61
62
63
64
# File 'app/models/operations/feature_flag.rb', line 58

def for_unleash_client(project, environment)
  includes(strategies: [:scopes, :user_list])
    .where(project: project)
    .merge(Operations::FeatureFlags::Scope.on_environment(environment))
    .reorder(:id)
    .references(:operations_scopes)
end


76
77
78
# File 'app/models/operations/feature_flag.rb', line 76

def link_reference_pattern
  @link_reference_pattern ||= compose_link_reference_pattern('feature_flags', %r{(?<feature_flag>\d+)/edit})
end

.preload_relationsObject



54
55
56
# File 'app/models/operations/feature_flag.rb', line 54

def preload_relations
  preload(strategies: [:scopes, :user_list])
end

.reference_patternObject



70
71
72
73
74
# File 'app/models/operations/feature_flag.rb', line 70

def reference_pattern
  @reference_pattern ||= %r{
    #{Regexp.escape(reference_prefix)}(#{::Project.reference_pattern}\/)?(?<feature_flag>\d+)#{Regexp.escape(reference_postfix)}
  }x
end

.reference_postfixObject



80
81
82
# File 'app/models/operations/feature_flag.rb', line 80

def reference_postfix
  ']'
end

.reference_prefixObject



66
67
68
# File 'app/models/operations/feature_flag.rb', line 66

def reference_prefix
  '[feature_flag:'
end

Instance Method Details

#hook_attrsObject



103
104
105
106
107
108
109
110
# File 'app/models/operations/feature_flag.rb', line 103

def hook_attrs
  {
    id: id,
    name: name,
    description: description,
    active: active
  }
end


92
93
94
95
96
97
98
99
100
101
# File 'app/models/operations/feature_flag.rb', line 92

def related_issues(current_user, preload:)
  issues = ::Issue
    .select('issues.*, operations_feature_flags_issues.id AS link_id')
    .joins(:feature_flag_issues)
    .where(operations_feature_flags_issues: { feature_flag_id: id })
    .order('operations_feature_flags_issues.id ASC')
    .includes(preload)

  Ability.issues_readable_by_user(issues, current_user)
end

#to_reference(from = nil, full: false) ⇒ Object



85
86
87
88
89
90
# File 'app/models/operations/feature_flag.rb', line 85

def to_reference(from = nil, full: false)
  project
    .to_reference_base(from, full: full)
    .then { |reference_base| reference_base.present? ? "#{reference_base}/" : nil }
    .then { |reference_base| "#{self.class.reference_prefix}#{reference_base}#{iid}#{self.class.reference_postfix}" }
end