Class: MemoryIO::Util::FilePermission

Inherits:
Object
  • Object
show all
Defined in:
lib/memory_io/util.rb

Overview

A simple class to be returned for getting file permissions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FilePermission

Returns a new instance of FilePermission.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/memory_io/util.rb', line 15

def initialize(file)
  stat = File.stat(file)
  @readable = stat.readable_real?
  @writable = stat.writable_real?
  # we do a trick here because /proc/[pid]/mem might be marked as writeable but fails at sysopen.
  begin
    @readable && File.open(file, 'rb').close
  rescue Errno::EACCES
    @readable = false
  end
  begin
    @writable && File.open(file, 'wb').close
  rescue Errno::EACCES
    @writable = false
  end
end

Instance Attribute Details

#readableObject (readonly) Also known as: readable?

Returns the value of attribute readable.



10
11
12
# File 'lib/memory_io/util.rb', line 10

def readable
  @readable
end

#writableObject (readonly) Also known as: writable?

Returns the value of attribute writable.



10
11
12
# File 'lib/memory_io/util.rb', line 10

def writable
  @writable
end