Class: History

Inherits:
Object
  • Object
show all
Defined in:
lib/base/history.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dev = nil) ⇒ History

Returns a new instance of History.



6
7
8
9
# File 'lib/base/history.rb', line 6

def initialize dev=nil
	@dev=dev
	@dev=Dev.new if @dev.nil?
end

Instance Attribute Details

#devObject

Returns the value of attribute dev.



4
5
6
# File 'lib/base/history.rb', line 4

def dev
  @dev
end

Instance Method Details

#add_command(command) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/base/history.rb', line 24

def add_command command
	code="0"
	code="X" if command[:exit_code] !=0
	directory=command[:directory].gsub(@dev.root_dir,'').gsub('/','-')
	name="#{command[:input]}.#{code}.#{directory}.json"
	filename="#{@dev.log_dir}/#{name}"
	puts "add command #{filename}" if @dev.debug?
	File.open(filename,'w'){|f|f.write(command.to_json)}
end

#get_commands(pattern) ⇒ Object

.0. for 0 exit codes .X. for non 0 exit codes project name is contained in directory name



14
15
16
17
18
19
20
21
22
# File 'lib/base/history.rb', line 14

def get_commands pattern
	commands=Array.new
	Dir.chdir(@dev.log_dir) do
		Dir.glob("*#{pattern.gsub('/','-')}*.*").each{|logfile|
			commands << Command.new(JSON.parse(IO.read(logfile)))
		}
	end
	commands
end

#get_wrk_command(project_fullname) ⇒ Object



34
35
36
37
38
# File 'lib/base/history.rb', line 34

def get_wrk_command project_fullname
	commands=get_commands("#{project_fullname}".gsub('/','-'))
	return commands[0] if commands.length > 0
	nil
end