Class: Mongify::Mongoid::CLI::Command::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/mongify/mongoid/cli/command/worker.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(translation_file = nil, output_dir = nil, options = {}) ⇒ Worker

Returns a new instance of Worker.



12
13
14
15
16
# 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

Instance Attribute Details

#viewObject

Returns the value of attribute view.



9
10
11
# File 'lib/mongify/mongoid/cli/command/worker.rb', line 9

def view
  @view
end

Instance Method Details

#execute(view) ⇒ Object

Executes the worked based on a given command



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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_folderObject

Folder location of the output



38
39
40
41
# 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