Class: Mongify::Mongoid::CLI::Application
- Inherits:
-
Object
- Object
- Mongify::Mongoid::CLI::Application
- Defined in:
- lib/mongify/mongoid/cli/application.rb
Overview
Represents an instance of a Mongify Mongoid application. This is the entry point for all invocations of Mongify from the command line.
Constant Summary collapse
- STATUS_SUCCESS =
Successful execution exit code
0
- STATUS_ERROR =
Failed execution exit code
1
Instance Method Summary collapse
-
#execute! ⇒ Object
Runs the application.
-
#initialize(arguments = [], stdin = $stdin, stdout = $stdout) ⇒ Application
constructor
A new instance of Application.
-
#output(message) ⇒ Object
Sends output to the UI.
-
#report_error ⇒ Object
Sets status code as failure (or error).
-
#report_success ⇒ Object
Sets status code as successful.
Constructor Details
#initialize(arguments = [], stdin = $stdin, stdout = $stdout) ⇒ Application
Returns a new instance of Application.
17 18 19 20 21 |
# File 'lib/mongify/mongoid/cli/application.rb', line 17 def initialize(arguments=[], stdin=$stdin, stdout=$stdout) arguments = ['-h'] if arguments.empty? @options = Options.new(arguments) @status = STATUS_SUCCESS end |
Instance Method Details
#execute! ⇒ Object
Runs the application
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mongify/mongoid/cli/application.rb', line 24 def execute! begin cmd = @options.parse return cmd.execute(self) rescue Error => error $stderr.puts "ERROR: \n#{error}" $stderr.puts "\nIf this is an issue that you can not figure out, feel free to submit an issue report at:" $stderr.puts "https://github.com/anlek/mongify-mongoid/issues" report_error rescue Exception => error $stderr.puts "UNKNOWN ERROR: \n#{error}" $stderr.puts "\nWe are not sure what happen but feel free to submit this issue report at:" $stderr.puts "https://github.com/anlek/mongify-mongoid/issues" $stderr.puts "" report_error raise error end end |
#output(message) ⇒ Object
Sends output to the UI
44 45 46 |
# File 'lib/mongify/mongoid/cli/application.rb', line 44 def output() UI.puts() end |
#report_error ⇒ Object
Sets status code as failure (or error)
54 55 56 |
# File 'lib/mongify/mongoid/cli/application.rb', line 54 def report_error @status = STATUS_ERROR end |
#report_success ⇒ Object
Sets status code as successful
49 50 51 |
# File 'lib/mongify/mongoid/cli/application.rb', line 49 def report_success @status = STATUS_SUCCESS end |