class Mongify::Mongoid::CLI::Command::Worker

A command to run the different commands in the application (related to Mongifying).

Attributes

view[RW]

Public Class Methods

new(translation_file=nil, output_dir=nil, options={}) click to toggle source
# File lib/mongify/mongoid/cli/command/worker.rb, line 12
def initialize(translation_file=nil, output_dir=nil, options={})
  @translation_file = translation_file
  @output_dir = output_dir
  @options = options
end

Public Instance Methods

execute(view) click to toggle source

Executes the worked based on a given command

# File lib/mongify/mongoid/cli/command/worker.rb, line 19
def execute(view)
  self.view = view

  valid_translation? @translation_file
  prevent_overwrite! (@options)

  unless File.directory?(output_folder)
     FileUtils.mkdir_p(output_folder)
  end

  @generator = Mongify::Mongoid::Generator.new(@translation_file, output_folder)
  @generator.process

  output_success_message

  view.report_success
end
output_folder() click to toggle source

Folder location of the output

# File lib/mongify/mongoid/cli/command/worker.rb, line 38
def output_folder
  @output_dir = File.join(Dir.pwd, "models") if @output_dir.nil?
  @output_dir
end

Private Instance Methods

output_success_message() click to toggle source
# File lib/mongify/mongoid/cli/command/worker.rb, line 57
def output_success_message
  view.output("\nSuccessfully processed #{@generator.models.count} models")
  view.output("You can find your files in #{output_folder}")
  view.output("\nThank you for using Mongify and Mongify-Mongoid!")
  view.output("If you have any issues, please feel free to report them at:\nhttps://github.com/anlek/mongify-mongoid/issues")
  view.output("")
end
prevent_overwrite!(options={}) click to toggle source
# File lib/mongify/mongoid/cli/command/worker.rb, line 53
def prevent_overwrite! options={}
  raise OverwritingFolder, "Output folder (#{output_folder}) already exists, for your safety we can't continue, pass -f force an overwrite" if File.exists?(output_folder) && !options[:overwrite]
end
valid_translation?(translation_file) click to toggle source

Verify tranlsation file exists

# File lib/mongify/mongoid/cli/command/worker.rb, line 48
def valid_translation? translation_file
  raise TranslationFileNotFound, "Translation file is required" unless translation_file
  raise TranslationFileNotFound, "Unable to find Translation File #{translation_file}" unless File.exists?(translation_file)
end