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.
6 7 8 |
# File 'lib/base/history.rb', line 6 def dev @dev end |
Instance Method Details
#add_command(command) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/base/history.rb', line 26 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
16 17 18 19 20 21 22 23 24 |
# File 'lib/base/history.rb', line 16 def get_commands(pattern) commands = [] Dir.chdir(@dev.log_dir) do Dir.glob("*#{pattern.gsub("/", "-")}*.*").each do |logfile| commands << Command.new(JSON.parse(IO.read(logfile))) end end commands end |
#get_wrk_command(project_fullname) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/base/history.rb', line 36 def get_wrk_command(project_fullname) commands = get_commands(project_fullname.to_s.gsub("/", "-")) return commands[0] if commands.length.positive? nil end |