Sha256: a869fe29e310d78643df045293e9aee2abb4edadd12148637487c8bc8b6c66f8
Contents?: true
Size: 748 Bytes
Versions: 7
Compression:
Stored size: 748 Bytes
Contents
require "fileutils" require "ostruct" require "yaml" module CommandInterceptor class Command < OpenStruct end BIN_PATH = File.expand_path("../bin", __FILE__) LOG_PATH = File.expand_path("../../../tmp/commands.yml", __FILE__) def self.setup ENV["PATH"] = "#{BIN_PATH}:#{ENV["PATH"]}" end def self.intercept(name) FileUtils.mkdir_p(File.dirname(LOG_PATH)) FileUtils.touch(LOG_PATH) command = { "env" => ENV.to_hash, "name" => name, "args" => ARGV } commands = self.commands << command File.write(LOG_PATH, YAML.dump(commands)) end def self.commands (File.exist?(LOG_PATH) && YAML.load_file(LOG_PATH) || []).map { |c| Command.new(c) } end def self.reset FileUtils.rm_f(LOG_PATH) end end
Version data entries
7 entries across 7 versions & 3 rubygems