Class: Docman::ExecuteScriptCmd
- Defined in:
- lib/docman/commands/execute_script_cmd.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
Methods inherited from Command
#add_action, #add_actions, #config, create, #describe, #initialize, #perform, #prefix, register_command, #replace_placeholder, #run_actions, #run_with_hooks
Methods included from Logging
#log, logger, #logger, #prefix, #properties_info, #with_logging
Constructor Details
This class inherits a constructor from Docman::Command
Instance Method Details
#execute ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/docman/commands/execute_script_cmd.rb', line 18 def execute Dir.chdir self['execution_dir'] logger.info "Script execution: #{self['location']}" params = self['params'].nil? ? '' : prepare_params(self['params']) # Fix for ^M issue when saved from GitLab or windows. `cat #{self['location']} | tr -d '\r' > #{self['location']}-tmp` `rm -f #{self['location']}` `mv #{self['location']}-tmp #{self['location']}` `chmod a+x #{self['location']}` logger.info `#{self['location']} #{params}` $?.exitstatus end |
#prepare_params(params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/docman/commands/execute_script_cmd.rb', line 32 def prepare_params(params) result = [] params.each do |param| case param when 'environment' result << @context.environment_name end end result.join(' ') end |
#validate_command ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/docman/commands/execute_script_cmd.rb', line 7 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 |