Sha256: f1e325908be82839542b24eb85e9bf24600bd2ed2328f73dc0f9c7732a9d8dab

Contents?: true

Size: 1.3 KB

Versions: 17

Compression:

Stored size: 1.3 KB

Contents

module DevboxLauncher
  class Watchman

    attr_reader :dir

    def initialize(dir:)
      @dir = dir
    end

    def trigger(command)
      UNIXSocket.open(sockname) do |socket|
        root = Pathname.new(dir).expand_path.to_s
        result = RubyWatchman.query(['watch-list'], socket)
        roots = result['roots']
        if !roots.include?(root)
          # this path isn't being watched yet; try to set up watch
          result = RubyWatchman.query(['watch-project', root], socket)

          # root_restrict_files setting may prevent Watchman from working
          raise "Unable to watch #{dir}" if result.has_key?('error')
        end

        query = ['trigger', root, {
          'name' => 'mutagen-sync',
          'expression' => ['match', '**/*', 'wholename'],
          'command' => command.split(" "),
        }]
        paths = RubyWatchman.query(query, socket)

        # could return error if watch is removed
        if paths.has_key?('error')
          raise "Unable to set trigger. Error: #{paths['error']}"
        end
      end
    end

    def sockname
      sockname = RubyWatchman.load(
        %x{watchman --output-encoding=bser get-sockname}
      )['sockname']

      if !$?.exitstatus.zero?
        raise "Failed to connect to watchman. Is it running?"
      end

      sockname
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
devbox_launcher-1.1.1 lib/devbox_launcher/watchman.rb
devbox_launcher-1.1.0 lib/devbox_launcher/watchman.rb
devbox_launcher-1.0.0 lib/devbox_launcher/watchman.rb
devbox_launcher-0.7.1 lib/devbox_launcher/watchman.rb
devbox_launcher-0.7.0 lib/devbox_launcher/watchman.rb
devbox_launcher-0.6.1 lib/devbox_launcher/watchman.rb
devbox_launcher-0.6.0 lib/devbox_launcher/watchman.rb
devbox_launcher-0.5.2 lib/devbox_launcher/watchman.rb
devbox_launcher-0.5.1 lib/devbox_launcher/watchman.rb
devbox_launcher-0.5.0 lib/devbox_launcher/watchman.rb
devbox_launcher-0.4.0 lib/devbox_launcher/watchman.rb
devbox_launcher-0.3.5 lib/devbox_launcher/watchman.rb
devbox_launcher-0.3.4 lib/devbox_launcher/watchman.rb
devbox_launcher-0.3.3 lib/devbox_launcher/watchman.rb
devbox_launcher-0.3.2 lib/devbox_launcher/watchman.rb
devbox_launcher-0.3.1 lib/devbox_launcher/watchman.rb
devbox_launcher-0.3.0 lib/devbox_launcher/watchman.rb