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.


8
9
10
11
# File 'lib/base/history.rb', line 8

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

Instance Attribute Details

#devObject

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