Class: History
- Inherits:
-
Object
- Object
- History
- Defined in:
- lib/base/history.rb
Instance Attribute Summary collapse
-
#dev ⇒ Object
Returns the value of attribute dev.
Instance Method Summary collapse
- #add_command(command) ⇒ Object
-
#get_commands(pattern) ⇒ Object
.0.
- #get_wrk_command(project_fullname) ⇒ Object
-
#initialize(dev = nil) ⇒ History
constructor
A new instance of History.
Constructor Details
Instance Attribute Details
#dev ⇒ Object
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 |