Class: FileMover

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/uploaders/file_mover.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(file_path, update_field = :description, from_model:, to_model:) ⇒ FileMover

Returns a new instance of FileMover.


8
9
10
11
12
13
14
# File 'app/uploaders/file_mover.rb', line 8

def initialize(file_path, update_field = :description, from_model:, to_model:)
  @secret = File.split(File.dirname(file_path)).last
  @file_name = File.basename(file_path)
  @from_model = from_model
  @to_model = to_model
  @update_field = update_field
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name


6
7
8
# File 'app/uploaders/file_mover.rb', line 6

def file_name
  @file_name
end

#from_modelObject (readonly)

Returns the value of attribute from_model


6
7
8
# File 'app/uploaders/file_mover.rb', line 6

def from_model
  @from_model
end

#secretObject (readonly)

Returns the value of attribute secret


6
7
8
# File 'app/uploaders/file_mover.rb', line 6

def secret
  @secret
end

#to_modelObject (readonly)

Returns the value of attribute to_model


6
7
8
# File 'app/uploaders/file_mover.rb', line 6

def to_model
  @to_model
end

#update_fieldObject (readonly)

Returns the value of attribute update_field


6
7
8
# File 'app/uploaders/file_mover.rb', line 6

def update_field
  @update_field
end

Instance Method Details

#executeObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/uploaders/file_mover.rb', line 16

def execute
  temp_file_uploader.retrieve_from_store!(file_name)

  return unless valid?

  uploader.retrieve_from_store!(file_name)

  move

  if update_markdown
    update_upload_model
    uploader.schedule_background_upload
  end
end