class DTK::Client::Operation::Module::Stage

Public Class Methods

execute(args = Args.new) click to toggle source
# File lib/client/operation/module/stage.rb, line 21
def self.execute(args = Args.new)
  wrap_operation(args) do |args|
    module_ref      = args.required(:module_ref)
    remove_existing = args[:remove_existing]
    service_name    = args[:service_name] 
    force           = args[:force]
    directory_path  = args[:directory_path]

    post_body = PostBody.new(
      :namespace              => module_ref.namespace,
      :module_name            => module_ref.module_name,
      :assembly_name?         => args.required(:assembly_name),
      :version?               => args[:version],
      :context_service_names? => args[:context_service_names],
      :is_base?               => args[:is_base]
    )
    
    error_msg = "To allow stage to go through, invoke 'dtk push' to push the changes to server before invoking stage again"
    GitRepo.modified_with_diff?(directory_path || module_ref.client_dir_path, { :error_msg => error_msg, :command => 'stage' }) unless force
    service_name ||= rest_post("#{BaseRoute}/generate_service_name", post_body).data
    base_path = ClientModuleDir.ret_base_path(:service, service_name)
    
    raise Error::Usage, "Directory '#{base_path}' is not empty; it must be deleted or moved before retrying the command" if ClientModuleDir.local_dir_exists?(:service, service_name) 

    post_body.merge!(:service_name => service_name)
    response = rest_post("#{BaseRoute}/stage", post_body)

    service_instance = response.required(:service, :name)

    clone_args = {
      :module_ref       => module_ref,
      :base_module      => response.required(:base_module),
      :nested_modules   => response.required(:nested_modules),
      :service_instance => service_instance,
      :remove_existing  => remove_existing
    }
    message = ClientModuleDir::ServiceInstance.clone(clone_args)
    target_dir = message.data(:target_repo_dir)

    OsUtil.print_info("Service instance '#{service_instance}' has been created. In order to work with service instance, please navigate to: #{target_dir}") 
  end
end