<commit_before>require 'forwardable'
require 'memfs/filesystem_access'

module MemFs
  class File
    class Stat
      extend Forwardable
      include FilesystemAccess

      attr_reader :entry

      def_delegators :entry,
                     :atime,
                     :blksize,
                     :ctime,
                     :dev,
                     :gid,
                     :ino,
                     :mode,
                     :mtime,
                     :uid

      def directory?
        entry.is_a?(Fake::Directory)
      end

      def executable?
        if owned?
          !!(mode & Fake::Entry::UEXEC).nonzero?
        elsif grpowned?
          !!(mode & Fake::Entry::GEXEC).nonzero?
        else
          !!(mode & Fake::Entry::OEXEC).nonzero?
        end
      end

      def executable_real?
        if Process.uid == uid
          !!(mode & Fake::Entry::UEXEC).nonzero?
        elsif Process.gid == gid
          !!(mode & Fake::Entry::GEXEC).nonzero?
        else
          !!(mode & Fake::Entry::OEXEC).nonzero?
        end
      end

      def file?
        entry.is_a?(Fake::File)
      end

      def grpowned?
        gid == Process.egid
      end

      def initialize(path, dereference = false)
        entry = fs.find!(path)
        @entry = dereference ? entry.dereferenced : entry
      end

      def owned?
        uid == Process.euid
      end

      def readable?
        if owned?
          !!(mode & Fake::Entry::UREAD).nonzero?
        elsif grpowned?
          !!(mode & Fake::Entry::GREAD).nonzero?
        else
          !!world_readable?
        end
      end

      def readable_real?
        if Process.uid == uid
          !!(mode & Fake::Entry::UREAD).nonzero?
        elsif Process.gid == gid
          !!(mode & Fake::Entry::GREAD).nonzero?
        else
          !!world_readable?
        end
      end

      def sticky?
        !!(entry.mode & Fake::Entry::USTICK).nonzero?
      end

      def symlink?
        entry.is_a?(Fake::Symlink)
      end

      def world_readable?
        entry.mode - 0100000 if (entry.mode & Fake::Entry::OREAD).nonzero?
      end

      def world_writable?
        entry.mode - 0100000 if (entry.mode & Fake::Entry::OWRITE).nonzero?
      end

      def writable?
        if owned?
          !!(mode & Fake::Entry::UWRITE).nonzero?
        elsif grpowned?
          !!(mode & Fake::Entry::GWRITE).nonzero?
        else
          !!world_writable?
        end
      end

      def writable_real?
        if Process.uid == uid
          !!(mode & Fake::Entry::UWRITE).nonzero?
        elsif Process.gid == gid
          !!(mode & Fake::Entry::GWRITE).nonzero?
        else
          !!world_writable?
        end
      end
    end
  end
end
<commit_msg>Refactoring the Stat query methods<commit_after>require 'forwardable'
require 'memfs/filesystem_access'

module MemFs
  class File
    class Stat
      extend Forwardable
      include FilesystemAccess

      attr_reader :entry

      def_delegators :entry,
                     :atime,
                     :blksize,
                     :ctime,
                     :dev,
                     :gid,
                     :ino,
                     :mode,
                     :mtime,
                     :uid

      def directory?
        entry.is_a?(Fake::Directory)
      end

      def executable?
        if owned?
          !!(mode & Fake::Entry::UEXEC).nonzero?
        elsif grpowned?
          !!(mode & Fake::Entry::GEXEC).nonzero?
        else
          !!(mode & Fake::Entry::OEXEC).nonzero?
        end
      end

      def executable_real?
        if Process.uid == uid
          !!(mode & Fake::Entry::UEXEC).nonzero?
        elsif Process.gid == gid
          !!(mode & Fake::Entry::GEXEC).nonzero?
        else
          !!(mode & Fake::Entry::OEXEC).nonzero?
        end
      end

      def file?
        entry.is_a?(Fake::File)
      end

      def grpowned?
        gid == Process.egid
      end

      def initialize(path, dereference = false)
        entry = fs.find!(path)
        @entry = dereference ? entry.dereferenced : entry
      end

      def owned?
        uid == Process.euid
      end

      def readable?
        user_readable? || group_readable? || !!world_readable?
      end

      def readable_real?
        user_readable_real? || group_readable_real? || !!world_readable?
      end

      def sticky?
        !!(entry.mode & Fake::Entry::USTICK).nonzero?
      end

      def symlink?
        entry.is_a?(Fake::Symlink)
      end

      def world_readable?
        entry.mode - 0100000 if (entry.mode & Fake::Entry::OREAD).nonzero?
      end

      def world_writable?
        entry.mode - 0100000 if (entry.mode & Fake::Entry::OWRITE).nonzero?
      end

      def writable?
        user_writable? || group_writable? || !!world_writable?
      end

      def writable_real?
        user_writable_real? || group_writable_real? || !!world_writable?
      end

      private

      def group_readable?
        grpowned? && !!(mode & Fake::Entry::GREAD).nonzero?
      end

      def group_readable_real?
        Process.gid == gid && !!(mode & Fake::Entry::GREAD).nonzero?
      end

      def group_writable?
        grpowned? && !!(mode & Fake::Entry::GWRITE).nonzero?
      end

      def group_writable_real?
        Process.gid == gid && !!(mode & Fake::Entry::GWRITE).nonzero?
      end

      def user_readable?
        owned? && !!(mode & Fake::Entry::UREAD).nonzero?
      end

      def user_readable_real?
        Process.uid == uid && !!(mode & Fake::Entry::UREAD).nonzero?
      end

      def user_writable?
        owned? && !!(mode & Fake::Entry::UWRITE).nonzero?
      end

      def user_writable_real?
        Process.uid == uid && !!(mode & Fake::Entry::UWRITE).nonzero?
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11371467953135768, 'fraction_numerical': 0.004824259131633356, 'mean_word_length': 1.5926753014738724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1320907', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1737, 'n_words': 373}