File: file.rb

package info (click to toggle)
ruby-ox 2.14.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,504 kB
  • sloc: xml: 39,683; ansic: 9,626; ruby: 6,441; sh: 47; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,675 bytes parent folder | download | duplicates (2)
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
require 'etc'

module Sample
  class File
    attr_accessor :name, :ctime, :mtime, :size, :owner, :group, :permissions

    def initialize(filename)
      @name = ::File.basename(filename)
      stat = ::File.stat(filename)
      @ctime = stat.ctime
      @mtime = stat.mtime
      @size = stat.size
      @owner = Etc.getpwuid(stat.uid).name
      @group = Etc.getgrgid(stat.gid).name
      if false
        @permissions = {
          'user' => {
            'read' => (0 != (stat.mode & 0x0100)),
            'write' => (0 != (stat.mode & 0x0080)),
            'execute' => (0 != (stat.mode & 0x0040))
          },
          'group' => {
            'read' => (0 != (stat.mode & 0x0020)),
            'write' => (0 != (stat.mode & 0x0010)),
            'execute' => (0 != (stat.mode & 0x0008))
          },
          'other' => {
            'read' => (0 != (stat.mode & 0x0004)),
            'write' => (0 != (stat.mode & 0x0002)),
            'execute' => (0 != (stat.mode & 0x0001))
          }
        }
      else
        @permissions = {
          'user' => [0 != (stat.mode & 0x0100) ? 'r' : '-',
                     0 != (stat.mode & 0x0080) ? 'w' : '-',
                     0 != (stat.mode & 0x0040) ? 'x' : '-'].join(''),
          'group' => [0 != (stat.mode & 0x0020) ? 'r' : '-',
                      0 != (stat.mode & 0x0010) ? 'w' : '-',
                      0 != (stat.mode & 0x0008) ? 'x' : '-'].join(''),
          'other' => [0 != (stat.mode & 0x0004) ? 'r' : '-',
                      0 != (stat.mode & 0x0002) ? 'w' : '-',
                      0 != (stat.mode & 0x0001) ? 'x' : '-'].join('')
        }
      end
    end
  end # File
end # Sample