Sha256: f39b1a3ac40ffb85d1d604c130e28bba4fe271f2c77504c218138437046b8530

Contents?: true

Size: 1.42 KB

Versions: 33

Compression:

Stored size: 1.42 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.environment_name
        end
      end
      result.join(' ')
    end

  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
docman-0.0.44 lib/docman/commands/execute_script_cmd.rb
docman-0.0.43 lib/docman/commands/execute_script_cmd.rb
docman-0.0.42 lib/docman/commands/execute_script_cmd.rb
docman-0.0.41 lib/docman/commands/execute_script_cmd.rb
docman-0.0.40 lib/docman/commands/execute_script_cmd.rb
docman-0.0.39 lib/docman/commands/execute_script_cmd.rb
docman-0.0.38 lib/docman/commands/execute_script_cmd.rb
docman-0.0.37 lib/docman/commands/execute_script_cmd.rb
docman-0.0.36 lib/docman/commands/execute_script_cmd.rb
docman-0.0.35 lib/docman/commands/execute_script_cmd.rb
docman-0.0.34 lib/docman/commands/execute_script_cmd.rb
docman-0.0.33 lib/docman/commands/execute_script_cmd.rb
docman-0.0.32 lib/docman/commands/execute_script_cmd.rb
docman-0.0.31 lib/docman/commands/execute_script_cmd.rb
docman-0.0.30 lib/docman/commands/execute_script_cmd.rb
docman-0.0.29 lib/docman/commands/execute_script_cmd.rb
docman-0.0.28 lib/docman/commands/execute_script_cmd.rb
docman-0.0.27 lib/docman/commands/execute_script_cmd.rb
docman-0.0.26 lib/docman/commands/execute_script_cmd.rb
docman-0.0.25 lib/docman/commands/execute_script_cmd.rb