Module: RCL::Perms

Defined in:
lib/rcl/perms.rb

Class Method Summary collapse

Class Method Details

.check_dir(pathname) ⇒ Object

check that specified directory exists

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rcl/perms.rb', line 9

def self.check_dir(pathname)
  raise ArgumentError, 'nil pathname' if pathname.nil?
  raise ArgumentError, 'invalid pathname class' if pathname.class != String
  raise ArgumentError, 'empty pathname' if pathname.empty?
  raise ArgumentError, "#{pathname} does not exist" \
    if !File.exists?(pathname)
  raise ArgumentError, "#{pathname} is not a directory" \
    if !File.directory?(pathname)

  true
end

.check_dir_r(pathname) ⇒ Object

check that specified directory exists and is readable

Raises:

  • (ArgumenError)


22
23
24
25
26
27
28
# File 'lib/rcl/perms.rb', line 22

def self.check_dir_r(pathname)
  check_dir(pathname)
  raise ArgumenError, "#{pathname} is not readable" \
    if !File.readable?(pathname)

  true
end

.check_dir_rw(pathname) ⇒ Object

check that specified directory exists and is both readable and writable



40
41
42
43
44
45
46
# File 'lib/rcl/perms.rb', line 40

def self.check_dir_rw(pathname)
  check_dir(pathname)
  check_dir_r(pathname)
  check_dir_w(pathname)

  true
end

.check_dir_w(pathname) ⇒ Object

check that specified directory exists and is writable

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
# File 'lib/rcl/perms.rb', line 31

def self.check_dir_w(pathname)
  check_dir(pathname)
  raise ArgumentError, "#{pathname} is not writable" \
    if !File.writable?(pathname)

  true
end

.check_file(pathname) ⇒ Object

check that specified file exists

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rcl/perms.rb', line 49

def self.check_file(pathname)
  raise ArgumentError, 'nil pathname' if pathname.nil?
  raise ArgumentError, 'invalid pathname class' if pathname.class != String
  raise ArgumentError, 'empty pathname' if pathname.empty?
  raise ArgumentError, "#{pathname} does not exist" \
    if !File.exist?(pathname)
  raise ArgumentError, "#{pathname} is not a directory" \
    if !File.file?(pathname)

  true
end

.check_file_r(pathname) ⇒ Object

check that specified file exists and is readable

Raises:

  • (ArgumentError)


62
63
64
65
66
67
68
# File 'lib/rcl/perms.rb', line 62

def self.check_file_r(pathname)
  check_file(pathname)
  raise ArgumentError, "#{pathname} is not readable" \
    if !File.readable?(pathname)

  true
end

.check_file_rw(pathname) ⇒ Object

check that specified file exists and is both readable and writable



80
81
82
83
84
85
86
# File 'lib/rcl/perms.rb', line 80

def self.check_file_rw(pathname)
  check_file(pathname)
  check_file_r(pathname)
  check_file_w(pathname)

  true
end

.check_file_w(pathname) ⇒ Object

check that specified file exists and is writable

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
# File 'lib/rcl/perms.rb', line 71

def self.check_file_w(pathname)
  check_file(pathname)
  raise ArgumentError, "#{pathname} is not writable" \
    if !File.writable?(pathname)

  true
end

.check_owned(pathname) ⇒ Object

check file group and ownership

Raises:

  • (ArgumentError)


89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rcl/perms.rb', line 89

def self.check_owned(pathname)
  raise ArgumentError, 'nil pathname' if pathname.nil?
  raise ArgumentError, 'invalid pathname class' if pathname.class != String
  raise ArgumentError, 'empty pathname' if pathname.empty?
  raise ArgumentError, "#{pathname} does not have correct group" \
    if !File.grpowned?(pathname)
  raise ArgumentError, "#{pathname} does not have correct ownership" \
    if !File.owned?(pathname)

  true
end