Sha256: d3f75710a0f884210e5746f38c7e150cb73476df9d014e5e5c8bd0b4433065e5

Contents?: true

Size: 1.31 KB

Versions: 27

Compression:

Stored size: 1.31 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, @relative, @name = root, relative, name
      end

      attr_reader :root, :relative, :name

      def children
        child_relative = _join
        (Dir.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
    end
  end
end

Version data entries

27 entries across 27 versions & 6 rubygems

Version Path
sass-listen-3.0.7 lib/listen/record/entry.rb
listen-3.0.7 lib/listen/record/entry.rb
listen-3.0.6 lib/listen/record/entry.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/listen-3.0.5/lib/listen/record/entry.rb
listen-3.0.5 lib/listen/record/entry.rb
listen-3.0.4 lib/listen/record/entry.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/listen-3.0.3/lib/listen/record/entry.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/listen-3.0.3/lib/listen/record/entry.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/listen-3.0.3/lib/listen/record/entry.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/listen-3.0.3/lib/listen/record/entry.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/listen-3.0.3/lib/listen/record/entry.rb
geminfo-0.1.0 path/gems/listen-3.0.3/lib/listen/record/entry.rb
listen-3.0.3 lib/listen/record/entry.rb
listen-3.0.2 lib/listen/record/entry.rb
listen-3.0.1 lib/listen/record/entry.rb
listen-3.0.0 lib/listen/record/entry.rb
listen-2.10.1 lib/listen/record/entry.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/listen-2.8.6/lib/listen/record/entry.rb
listen-2.10.0 lib/listen/record/entry.rb
listen-2.9.0 lib/listen/record/entry.rb