Sha256: 88543fc1b3b6931be755d0817e2ebc9b295d98539715eb2949e61318781a23cb

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

module Docman
  class ExecuteScriptCmd < Docman::Command

    register_command :script


    def validate_command
      raise Docman::CommandValidationError.new("Please provide 'execution_dir' param") if self['execution_dir'].nil?
      raise Docman::CommandValidationError.new("Please provide 'location' param") if self['location'].nil?
      raise Docman::CommandValidationError.new("Please provide 'context'") if @context.nil?
      raise Docman::CommandValidationError.new("Context should be of type 'Info'") unless @context.is_a? Docman::Info
      replace_placeholder(self['execution_dir'])
      replace_placeholder(self['location'])
      raise Docman::CommandValidationError.new("Directory #{self['execution_dir']} not exists") unless File.directory? self['execution_dir']
      raise Docman::CommandValidationError.new("Script #{self['location']} not exists") unless File.file? self['location']
    end

    def execute
      Dir.chdir self['execution_dir']
      logger.info "Script execution: #{self['location']}"
      params = self['params'].nil? ? '' : prepare_params(self['params'])
      `chmod a+x #{self['location']}`
      logger.info `#{self['location']} #{params}`
      $?.exitstatus
    end

    def prepare_params(params)
      result = []
      params.each do |param|
        case param
          when 'environment'
            result << @context['docroot_config'].deploy_target['environment']
        end
      end
      result.join(' ')
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
docman-0.0.6 lib/docman/commands/execute_script_cmd.rb