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!, autoload_client_library, call, #call, command_name, configure, #current_user, #debug, description, disable!, disable_in_gem!, disabled?, #error, #fatal, #force_yes?, #info, inherited, #initialize, lang, language, #logger, options, #summarize, #summarize_hash, syntax, t, #table, #verbose?, warn_unauthenticated_users
Instance Method Details
#confirmed?(dataset) ⇒ Boolean
85
86
87
88
89
|
# File 'lib/quandl/command/tasks/delete.rb', line 85
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/quandl/command/tasks/delete.rb', line 63
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
36
37
38
39
40
41
|
# File 'lib/quandl/command/tasks/delete.rb', line 36
def delete_each_argument
args.each{|code| delete_with_pool(code) }
pool.shutdown
end
|
#delete_each_stdin ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/quandl/command/tasks/delete.rb', line 43
def delete_each_stdin
return error("Cannot delete datasets from STDIN unless --force-yes is set!") unless force_yes?
$stdin.each_line{|code| delete_with_pool(code) }
pool.shutdown
end
|
#delete_with_pool(code) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/quandl/command/tasks/delete.rb', line 51
def delete_with_pool(code)
code = code.to_s.strip.rstrip
if force_yes?
pool.process{ delete( code ) }
else
delete( code )
end
end
|
#execute ⇒ Object
29
30
31
32
33
34
|
# File 'lib/quandl/command/tasks/delete.rb', line 29
def execute
return delete_each_argument if args.first.present?
delete_each_stdin
end
|
#report(dataset) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/quandl/command/tasks/delete.rb', line 78
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
|