Sha256: 4d2ac3c280c29a05d729ae96eeacb8bdf5a2788bb279b291b645acc09afcb76c

Contents?: true

Size: 1.28 KB

Versions: 17

Compression:

Stored size: 1.28 KB

Contents

require 'forwardable'

module Aruba
  module Platforms
    # File System Status object
    #
    # This is a wrapper for File::Stat returning only a subset of information.
    class FilesystemStatus
      METHODS = [
        :executable?,
        :ctime,
        :atime,
        :mtime,
        :size
      ].freeze

      extend Forwardable

      private

      attr_reader :status

      public

      if RUBY_VERSION >= '1.9.3'
        def_delegators :@status, *METHODS
      else
        def_delegators :@status, :executable?, :ctime, :atime, :mtime, :size
      end

      def initialize(path)
        @status = File::Stat.new(path)
      end

      # Return permissions
      def mode
        format("%o", status.mode)[-4,4].gsub(/^0*/, '')
      end

      # Return owner
      def owner
        status.uid
      end

      # Return owning group
      def group
        status.gid
      end

      # Convert status to hash
      #
      # @return [Hash]
      #   A hash of values
      def to_h
        {
          :owner      => owner,
          :group      => group,
          :mode       => mode,
          :executable => executable?,
          :ctime      => ctime,
          :atime      => atime,
          :mtime      => mtime,
          :size       => size
        }
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
aruba-0.14.14 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.13 lib/aruba/platforms/filesystem_status.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/lib/aruba/platforms/filesystem_status.rb
aruba-0.14.12 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.11 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.10 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.9 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.8 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.7 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.6 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.5 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.4 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.3 lib/aruba/platforms/filesystem_status.rb
aruba-win-fix-0.14.2 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.2 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.1 lib/aruba/platforms/filesystem_status.rb
aruba-0.14.0 lib/aruba/platforms/filesystem_status.rb