Class: NeocitiesRed::Services::FileRemover

Inherits:
Object
  • Object
show all
Defined in:
lib/neocities_red/services/file_remover.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, filepath) ⇒ FileRemover

Returns a new instance of FileRemover.



10
11
12
13
14
# File 'lib/neocities_red/services/file_remover.rb', line 10

def initialize(client, filepath)
  @client = client
  @filepath = filepath
  @pastel = Pastel.new(eachline: "\n")
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/neocities_red/services/file_remover.rb', line 8

def client
  @client
end

#filepathObject

Returns the value of attribute filepath.



8
9
10
# File 'lib/neocities_red/services/file_remover.rb', line 8

def filepath
  @filepath
end

Instance Method Details

#removeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/neocities_red/services/file_remover.rb', line 16

def remove
  puts @pastel.bold("Deleting #{filepath} ...")

  response = @client.delete(filepath)

  puts @pastel.bold(response[:message]) if response[:result] == "error"

  if response[:result] == "error" && response[:error_type] == "file_exists"
    print @pastel.yellow.bold("EXISTS")
  elsif response[:result] == "success"
    print @pastel.green.bold("SUCCESS")
  end

  response
end