Sha256: d9745e72573163987babdcf1092b9ec0e4360d2c877c132d1f3cc6af4e8c67c6

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

class Command < Hash
	def initialize command

		if(command.kind_of?(String))
		  self[:input] = command
		  self[:timeout] = 0
		  self[:directory] = ''
		  self[:exit_code] = 0
		  self[:output] = ''
		  self[:error] = ''
		  self[:machine_name] = ''
		  self[:user_name] = ''
		  self[:start_time] = nil
		  self[:end_time] = nil
        end

        if(command.kind_of?(Hash))
        	command.each{|k,v|
        		self[k.to_sym]=v
        	}
        end
	end

	def execute

		Logger.start_command self

		pwd=Dir.pwd
		Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
		#print " " + Color.green + self[:input] + Color.clear

		self[:start_time]=Time.now
		timer=Timer.new
		if self[:input].include?('<%') && self[:input].include?('%>')
		  ruby = self[:input].gsub("<%","").gsub("%>","")

		  begin
		  	puts "eval(#{ruby})"
		    self[:output]=eval(ruby)
		  rescue
		  	puts "unable to eval(#{ruby})"
		  	raise "unable to eval(#{ruby})"
		  end

		  #puts " " + timer.elapsed_str
		  self[:elapsed] = timer.elapsed_str
		  self[:end_time] = Time.now
		else
			self[:output] = `#{self[:input]}`
			self[:elapsed] = timer.elapsed_str
			self[:end_time] = Time.now
			self[:exit_code]=$?.to_i
		end

        Dir.chdir(pwd) if pwd != Dir.pwd
		Logger.end_command self
	end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dev_tasks-1.0.27 lib/command.rb
dev_tasks-1.0.26 lib/command.rb
dev_tasks-1.0.25 lib/command.rb
dev_tasks-1.0.24 lib/command.rb