Sha256: 7ceb10e8da586be1b1d6ac48c5f28295d0b3bc9d0f1e8a0639b5795bbefbcc0c

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 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

      def_delegators :@status, *METHODS

      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

7 entries across 7 versions & 1 rubygems

Version Path
aruba-1.0.3 lib/aruba/platforms/filesystem_status.rb
aruba-1.0.2 lib/aruba/platforms/filesystem_status.rb
aruba-1.0.1 lib/aruba/platforms/filesystem_status.rb
aruba-1.0.0 lib/aruba/platforms/filesystem_status.rb
aruba-1.0.0.pre.alpha.5 lib/aruba/platforms/filesystem_status.rb
aruba-1.0.0.pre.alpha.4 lib/aruba/platforms/filesystem_status.rb
aruba-1.0.0.pre.alpha.3 lib/aruba/platforms/filesystem_status.rb