module StructCore::Watcher

Public Class Methods

rebuild(project_file) click to toggle source
# File lib/watch/watcher.rb, line 18
def self.rebuild(project_file)
        StructCore::SpecProcessor.new(project_file, false).process
rescue StandardError => err
        puts Paint[err, :red]
end
watch(directory) click to toggle source
# File lib/watch/watcher.rb, line 24
def self.watch(directory)
        project_file = nil
        project_file = File.join(directory, 'project.yml') if File.exist? File.join(directory, 'project.yml')
        project_file = File.join(directory, 'project.yaml') if File.exist? File.join(directory, 'project.yaml')
        project_file = File.join(directory, 'project.json') if File.exist? File.join(directory, 'project.json')
        project_file = File.join(directory, 'Specfile') if File.exist? File.join(directory, 'Specfile')

        if project_file.nil?
                puts Paint['Could not find a spec file in the current directory', :red]
                quit(-1)
        end

        rebuild(project_file)

        listener = Listen.to(directory, ignore: /\.xcodeproj/) do |modified, added, removed|
                if modified.include?(project_file) || !added.empty? || !removed.empty?
                        rebuild(project_file)
                end
        end
        listener.start # not blocking
        puts Paint['All files and folders within this directory are now being watched for changes...', :green]
        sleep
end