Class: Gitlab::GithubImport::Representation::NoteText

Inherits:
Object
  • Object
show all
Includes:
ExposeAttribute, ToHash
Defined in:
lib/gitlab/github_import/representation/note_text.rb

Constant Summary collapse

MODELS_ALLOWLIST =
[::Release, ::Note, ::Issue, ::MergeRequest].freeze
ModelNotSupported =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ExposeAttribute

#[]

Methods included from ToHash

#convert_value_for_to_hash, #to_hash

Constructor Details

#initialize(attributes) ⇒ NoteText

attributes - A Hash containing the event details. The keys of this

Hash (and any nested hashes) must be symbols.


51
52
53
# File 'lib/gitlab/github_import/representation/note_text.rb', line 51

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



17
18
19
# File 'lib/gitlab/github_import/representation/note_text.rb', line 17

def attributes
  @attributes
end

Class Method Details

.from_db_record(record) ⇒ Object

Builds a note text representation from DB record of Note or Release.

record - An instance of ‘Note`, `Release`, `Issue`, `MergeRequest` model



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/github_import/representation/note_text.rb', line 24

def self.from_db_record(record)
  check_record_class!(record)

  record_type = record.class.name
  # only column for note is different along MODELS_ALLOWLIST
  text = record.is_a?(::Note) ? record.note : record.description
  new(
    record_db_id: record.id,
    record_type: record_type,
    text: text,
    iid: record.try(:iid),
    tag: record.try(:tag),
    noteable_type: record.try(:noteable_type)
  )
end

.from_json_hash(raw_hash) ⇒ Object



40
41
42
# File 'lib/gitlab/github_import/representation/note_text.rb', line 40

def self.from_json_hash(raw_hash)
  new Representation.symbolize_hash(raw_hash)
end

Instance Method Details

#github_identifiersObject



55
56
57
58
59
# File 'lib/gitlab/github_import/representation/note_text.rb', line 55

def github_identifiers
  {
    db_id: record_db_id
  }.merge(record_type_specific_attribute)
end