Sha256: 8d1edeaedba3122d395103c3e04abd8e2d983c02abb7f4c9b02153022cc83182

Contents?: true

Size: 1.68 KB

Versions: 52

Compression:

Stored size: 1.68 KB

Contents

module Listen
  # @private api
  class Record
    # Represents a directory entry (dir or file)
    class Entry
      # file: "/home/me/watched_dir", "app/models", "foo.rb"
      # dir, "/home/me/watched_dir", "."
      def initialize(root, relative, name = nil)
        @root = root
        @relative = relative
        @name = name
      end

      attr_reader :root, :relative, :name

      def children
        child_relative = _join
        (_entries(sys_path) - %w(. ..)).map do |name|
          Entry.new(@root, child_relative, name)
        end
      end

      def meta
        lstat = ::File.lstat(sys_path)
        { mtime: lstat.mtime.to_f, mode: lstat.mode }
      end

      # record hash is e.g.
      # if @record["/home/me/watched_dir"]["project/app/models"]["foo.rb"]
      # if @record["/home/me/watched_dir"]["project/app"]["models"]
      # record_dir_key is "project/app/models"
      def record_dir_key
        ::File.join(*[@relative, @name].compact)
      end

      def sys_path
        # Use full path in case someone uses chdir
        ::File.join(*[@root, @relative, @name].compact)
      end

      def real_path
        @real_path ||= ::File.realpath(sys_path)
      end

      private

      def _join
        args = [@relative, @name].compact
        args.empty? ? nil : ::File.join(*args)
      end

      def _entries(dir)
        return Dir.entries(dir) unless RUBY_ENGINE == 'jruby'

        # JRuby inconsistency workaround, see:
        # https://github.com/jruby/jruby/issues/3840
        exists = ::File.exist?(dir)
        directory = ::File.directory?(dir)
        return Dir.entries(dir) unless exists && !directory
        raise Errno::ENOTDIR, dir
      end
    end
  end
end

Version data entries

52 entries across 45 versions & 9 rubygems

Version Path
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/listen-3.2.1/lib/listen/record/entry.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/listen-3.1.5/lib/listen/record/entry.rb
listen-3.2.1 lib/listen/record/entry.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/record/entry.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/record/entry.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/record/entry.rb
listen-3.2.0 lib/listen/record/entry.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/record/entry.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/record/entry.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/record/entry.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/record/entry.rb