Class: Gitlab::Graphql::Deprecation

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/gitlab/graphql/deprecation.rb

Constant Summary collapse

REASONS =
{
  renamed: 'This was renamed.',
  alpha: 'This feature is in Alpha, and can be removed or changed at any point.'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason: nil, milestone: nil, replacement: nil) ⇒ Deprecation

Returns a new instance of Deprecation.


25
26
27
28
29
# File 'lib/gitlab/graphql/deprecation.rb', line 25

def initialize(reason: nil, milestone: nil, replacement: nil)
  @reason = reason.presence
  @milestone = milestone.presence
  @replacement = replacement.presence
end

Class Method Details

.parse(options) ⇒ Object


21
22
23
# File 'lib/gitlab/graphql/deprecation.rb', line 21

def self.parse(options)
  new(**options) if options
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql


31
32
33
34
35
36
37
# File 'lib/gitlab/graphql/deprecation.rb', line 31

def ==(other)
  return false unless other.is_a?(self.class)

  [reason_text, milestone, replacement] == [:reason_text, :milestone, :replacement].map do |attr|
    other.send(attr) # rubocop: disable GitlabSecurity/PublicSend
  end
end

#deprecation_reasonObject


76
77
78
79
80
81
82
# File 'lib/gitlab/graphql/deprecation.rb', line 76

def deprecation_reason
  [
    reason_text,
    replacement && "Please use `#{replacement}`.",
    "#{deprecated_in}."
  ].compact.join(' ')
end

#edit_description(original_description) ⇒ Object


62
63
64
65
66
67
# File 'lib/gitlab/graphql/deprecation.rb', line 62

def edit_description(original_description)
  @original_description = original_description
  return unless original_description

  original_description + description_suffix
end

#markdown(context: :inline) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gitlab/graphql/deprecation.rb', line 40

def markdown(context: :inline)
  parts = [
    "#{deprecated_in(format: :markdown)}.",
    reason_text,
    replacement_markdown.then { |r| "Use: #{r}." if r }
  ].compact

  case context
  when :block
    ['WARNING:', *parts].join("\n")
  when :inline
    parts.join(' ')
  end
end

#original_descriptionObject


69
70
71
72
73
74
# File 'lib/gitlab/graphql/deprecation.rb', line 69

def original_description
  return unless @original_description
  return @original_description if @original_description.ends_with?('.')

  "#{@original_description}."
end

#replacement_markdownObject


55
56
57
58
59
60
# File 'lib/gitlab/graphql/deprecation.rb', line 55

def replacement_markdown
  return unless replacement.present?
  return "`#{replacement}`" unless replacement.include?('.') # only fully qualified references can be linked

  "[`#{replacement}`](##{replacement.downcase.tr('.', '')})"
end