Class: DoiExtractor::Command
- Inherits:
-
Object
- Object
- DoiExtractor::Command
- Defined in:
- lib/doi_extractor/command.rb
Direct Known Subclasses
CancelCommand, CreateCommand, DownloadCommand, StatusCommand
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#std_out ⇒ Object
Returns the value of attribute std_out.
-
#user_input_callback ⇒ Object
Returns the value of attribute user_input_callback.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options, std_out = STDOUT, input_callback = nil) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(options, std_out = STDOUT, input_callback = nil) ⇒ Command
Returns a new instance of Command.
22 23 24 25 26 27 |
# File 'lib/doi_extractor/command.rb', line 22 def initialize(, std_out = STDOUT, input_callback = nil) @options = @std_out = std_out @user_input_callback = input_callback || default_input_callback @log = Logger::get_log end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
20 21 22 |
# File 'lib/doi_extractor/command.rb', line 20 def log @log end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/doi_extractor/command.rb', line 19 def @options end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
19 20 21 |
# File 'lib/doi_extractor/command.rb', line 19 def start_time @start_time end |
#std_out ⇒ Object
Returns the value of attribute std_out.
20 21 22 |
# File 'lib/doi_extractor/command.rb', line 20 def std_out @std_out end |
#user_input_callback ⇒ Object
Returns the value of attribute user_input_callback.
20 21 22 |
# File 'lib/doi_extractor/command.rb', line 20 def user_input_callback @user_input_callback end |
Class Method Details
.for(options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/doi_extractor/command.rb', line 4 def self.for() case .command when 'status' StatusCommand.new() when 'create' CreateCommand.new() when 'download' DownloadCommand.new() when 'cancel' CancelCommand.new() else raise "Invalid options: #{.inspect}" end end |
Instance Method Details
#execute ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/doi_extractor/command.rb', line 29 def execute begin @start_time = Time.now cmd = self.class.name.split('::').last.sub('Command', '') log.info "Starting #{cmd} Command:\n #{.to_hash}" say("starting #{cmd} Command", true) say("api: #{.api_uri}", true) say("path: #{.download_base_path}", true) _execute log.info "Finished #{cmd} Command" say("Finished in #{(Time.now - @start_time).round(2)} seconds", true) rescue CommandFailError => e log.error "#{e.class}: #{e.}\n #{e.backtrace.join("\n ")}" raise e rescue => e log.error "#{e.class}: #{e.}\n #{e.backtrace.join("\n ")}" raise CommandFailError.new('An Unexpected Error Has Occurred', e) end end |