Class: NeocitiesRed::Services::File::Remover

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) ⇒ Remover

Returns a new instance of Remover.



11
12
13
14
15
# File 'lib/neocities_red/services/file/remover.rb', line 11

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



9
10
11
# File 'lib/neocities_red/services/file/remover.rb', line 9

def client
  @client
end

#filepathObject

Returns the value of attribute filepath.



9
10
11
# File 'lib/neocities_red/services/file/remover.rb', line 9

def filepath
  @filepath
end

Instance Method Details

#removeObject



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

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