Class: Docman::YamlExecuteCmd
- Defined in:
- lib/docman/commands/yaml_execute_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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/docman/commands/yaml_execute_cmd.rb', line 16 def execute with_logging('yaml_execute') do Dir.chdir @context['full_build_path'] if self['environments'].nil? || self['environments'] == 'all' || self['environments'].include?(@context.environment_name) if self['providers'].nil? || self['providers'] == 'all' || self['providers'].include?(@context['provider']) commands = nil if self['source_type'] == 'file' yaml_file_name = self['yaml_file_name'].nil? ? '{unipipe,.unipipe,drupipe,.drupipe,build,.build}.{yaml,yml}' : self['yaml_file_name'] search_pathes = [] if @context['name'] == 'master' search_pathes.push File.join(@context['docroot_config'].config_dir, yaml_file_name) end search_pathes.push File.join(@context['full_build_path'], yaml_file_name) build_file = Dir.glob(search_pathes).first if not build_file.nil? build_file_yaml = YAML::load_file(build_file) commands = build_file_yaml[self['stage']] source = yaml_file_name end end chdir = '' if self['source_type'] == 'inline' commands = self['commands'] source = 'inline' if self.has_key?('exec_dir') chdir = self['exec_dir'] end end chdir_full = File.join(@context['full_build_path'], chdir) Dir.chdir chdir_full unless commands.nil? commands.each do |cmd| logger.info "Execute in #{chdir_full} from #{source}: #{cmd}" logger.info `#{cmd}` if $?.exitstatus > 0 raise "Command #{cmd} was failed" end end end Dir.chdir @context['full_build_path'] end end end end |
#validate_command ⇒ Object
6 7 8 9 10 |
# File 'lib/docman/commands/yaml_execute_cmd.rb', line 6 def validate_command raise "Please provide 'context'" if @context.nil? raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info raise "Both file & inline could not be se for this command" if self['yaml_file_name'] && self['inline'] end |