File: filesystem_status.rb

package info (click to toggle)
ruby-aruba 2.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 968 kB
  • sloc: javascript: 6,850; ruby: 4,010; makefile: 5
file content (72 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# frozen_string_literal: true

module Aruba
  module Platforms
    # File System Status object
    #
    # This is a wrapper for File::Stat returning only a subset of information.
    class FilesystemStatus
      private

      attr_reader :status

      public

      def executable?
        status.executable?
      end

      def ctime
        status.ctime
      end

      def atime
        status.atime
      end

      def mtime
        status.mtime
      end

      def size
        status.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