Class: Quandl::Command::Tasks::Delete
- Inherits:
-
Base
- Object
- Base
- Quandl::Command::Tasks::Delete
show all
- Defined in:
- lib/quandl/command/tasks/delete.rb
Instance Attribute Summary
Attributes inherited from Base
#args, #options, #request_timer
Instance Method Summary
collapse
Methods inherited from Base
#ask_yes_or_no, authenticated_users_only!, call, #call, command_name, configure, #current_user, #debug, description, disable!, disabled?, #error, #fatal, #force_yes?, #info, #initialize, #logger, options, #summarize, #summarize_hash, syntax, #table, #verbose?, warn_unauthenticated_users
Instance Method Details
#confirmed?(dataset) ⇒ Boolean
52
53
54
55
56
|
# File 'lib/quandl/command/tasks/delete.rb', line 52
def confirmed?(dataset)
return true if force_yes?
info summarize dataset.attributes.slice('source_code', 'code', 'name', 'from_date', 'to_date', 'column_names', 'created_at')
ask_yes_or_no
end
|
#delete(code) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/quandl/command/tasks/delete.rb', line 30
def delete(code)
return error("You must provide a code!") if code.blank?
dataset = Quandl::Client::Dataset.find(code)
return error(table(Quandl::Client::HTTP_STATUS_CODES[404], code)) if dataset.nil?
return report(dataset) unless dataset.exists?
return error("You must confirm deletion!") unless confirmed?(dataset)
dataset.destroy if dataset.exists?
report(dataset)
end
|
#delete_each_argument ⇒ Object
15
16
17
18
19
20
|
# File 'lib/quandl/command/tasks/delete.rb', line 15
def delete_each_argument
args.each do |code|
pool.process{ delete( code ) }
end
pool.shutdown
end
|
#delete_each_stdin ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/quandl/command/tasks/delete.rb', line 22
def delete_each_stdin
return error("Cannot delete datasets from STDIN unless --force-yes is set!") unless force_yes?
$stdin.each_line do |code|
pool.process{ delete( code.strip.rstrip ) }
end
pool.shutdown
end
|
#execute ⇒ Object
8
9
10
11
12
13
|
# File 'lib/quandl/command/tasks/delete.rb', line 8
def execute
return delete_each_argument if args.first.present?
delete_each_stdin
end
|
#report(dataset) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/quandl/command/tasks/delete.rb', line 45
def report(dataset)
m = table dataset.elapsed_request_time_ms, dataset.full_code
dataset.status == 200 ? info(table("Deleted", m)) : error(table(dataset.human_status, m))
end
|