class Mongify::Mongoid::CLI::Application

Represents an instance of a Mongify Mongoid application. This is the entry point for all invocations of Mongify from the command line.

Constants

STATUS_ERROR

Failed execution exit code

STATUS_SUCCESS

Successful execution exit code

Public Class Methods

new(arguments=[], stdin=$stdin, stdout=$stdout) click to toggle source
# 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

Public Instance Methods

execute!() click to toggle source

Runs the application

# 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) click to toggle source

Sends output to the UI

# File lib/mongify/mongoid/cli/application.rb, line 44
def output(message)
  UI.puts(message)
end
report_error() click to toggle source

Sets status code as failure (or error)

# File lib/mongify/mongoid/cli/application.rb, line 54
def report_error
  @status = STATUS_ERROR
end
report_success() click to toggle source

Sets status code as successful

# File lib/mongify/mongoid/cli/application.rb, line 49
def report_success
  @status = STATUS_SUCCESS
end