class Rubymon

Public Class Methods

dir() click to toggle source
# File lib/rubymon.rb, line 41
def self.dir #copy
    #@copy = copy
    begin
        puts "Can't run RubyMon in the home directory. Exiting ..." if Dir.pwd == Dir.home
        exit if Dir.pwd == Dir.home

        puts "Listening to directory: #{Dir.pwd} ..."

        listener = Listen.to(Dir.pwd, only: /\.rb$/) { |modified|
            if modified.join("").include?(".rb") && !modified.join("").start_with?("old_")
                #Rubymon.save_last(modified.join("")) if @copy == true
                #$file_last = modified.join("")
                #Rubymon.last_save(modified.join("")) if @copy == true
                $thr.exit
                $thr = Thread.new{Rubymon.execute_file(modified.join(""))}
            end
            }
        listener.start
        sleep
    rescue SystemExit, Interrupt => e
        puts "Exited program using CTRL + C"
    end
end
execute_file(modified) click to toggle source
# File lib/rubymon.rb, line 33
def self.execute_file modified
    puts "RubyMon executing file #{modified} ..."
    puts "************************\n"
    system("ruby #{modified}")
    puts "************************"
    puts "End of file ..." 
end
file(path, copy) click to toggle source
# File lib/rubymon.rb, line 65
def self.file path, copy
    @copy = copy
    begin
        puts "Can't run RubyMon in the home directory. Exiting ..." if Dir.pwd == Dir.home
        exit if Dir.pwd == Dir.home

        
        @path = path
        
        puts "#{Dir.pwd}/#{@path}"
        
        
        #if auto_execute == false
        #puts "Do you want to run the modified file #{modified}? (y/n)"
        #run_file = STDIN.gets.chomp
        puts "Listening to file: #{Dir.pwd}/#{@path} ..."

        listener = Listen.to(Dir.pwd) { |modified|
            if modified.join("") == @path && !modified.join("").start_with?("old_")
                Rubymon.save_last(modified.join("")) if @copy == true
                $file_last = modified.join("") if @copy == true
                Rubymon.last_save(modified.join("")) if @copy == true
                $thr.exit
                $thr = Thread.new{Rubymon.execute_file(modified.join(""))}
            end
            }
        listener.start
        sleep
    rescue SystemExit, Interrupt => e
        puts "Exited program using CTRL + C"
    end
end
last_save(file) click to toggle source
# File lib/rubymon.rb, line 7
def self.last_save file
    
    File.open(file, "r") do |file|
        while(line = file.gets)
            $file_content_last = []
            $file_content_last.push(line)
        end
    end
end
save_last(file) click to toggle source
# File lib/rubymon.rb, line 17
def self.save_last file
    puts $file_last
    puts file
    if $file_last != "" && $file_last == file
        File.delete("old_" + file) if File.file?("old_" + file)
        File.open("old_" + file, "w") do |file|
            file.truncate(0)
            $file_content_last.each do |line|
                file.write(line)
            end
        end
    else
        $file_content_last = []
    end
end