Module: FChange::Native::Flags

Defined in:
lib/rb-fchange/native/flags.rb

Overview

A module containing all the flags to be passed to FChange::Notifier#watch.

Constant Summary collapse

FILE_NOTIFY_CHANGE_FILE_NAME =

Any file name change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a file name.

0x00000001
FILE_NOTIFY_CHANGE_DIR_NAME =

Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory.

0x00000002
FILE_NOTIFY_CHANGE_ATTRIBUTES =

Any attribute change in the watched directory or subtree causes a change notification wait operation to return.

0x00000004
FILE_NOTIFY_CHANGE_SIZE =

Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.

0x00000008
FILE_NOTIFY_CHANGE_LAST_WRITE =

Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed

0x00000010
FILE_NOTIFY_CHANGE_LAST_ACCESS =

Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return.

0x00000020
FILE_NOTIFY_CHANGE_CREATION =

Any change to the creation time of files in the watched directory or subtree causes a change notification wait operation to return.

0x00000040
FILE_NOTIFY_CHANGE_SECURITY =

Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return.

0x00000100
FILE_NOTIFY_CHANGE_ALL_EVENTS =
(
  FILE_NOTIFY_CHANGE_DIR_NAME |
  FILE_NOTIFY_CHANGE_FILE_NAME |
  FILE_NOTIFY_CHANGE_LAST_WRITE
)

Class Method Summary collapse

Class Method Details

.from_mask(mask) ⇒ Array<Symbol>

Converts a bitmask from the C API into a list of flags.

Parameters:

  • mask (Fixnum)

Returns:

  • (Array<Symbol>)


69
70
71
72
73
74
# File 'lib/rb-fchange/native/flags.rb', line 69

def self.from_mask(mask)
  constants.map {|c| c.to_s}.select do |c|
    next false unless c =~ /^FILE_NOTIFY_CHANGE_/
    const_get(c) & mask != 0
  end.map {|c| c.sub("FILE_NOTIFY_CHANGE_", "").downcase.to_sym} - [:all_events]
end

.to_mask(flags) ⇒ Fixnum

Converts a list of flags to the bitmask that the C API expects.

Parameters:

  • flags (Array<Symbol>)

Returns:

  • (Fixnum)


60
61
62
63
# File 'lib/rb-fchange/native/flags.rb', line 60

def self.to_mask(flags)
  flags.map {|flag| const_get("FILE_NOTIFY_CHANGE_#{flag.to_s.upcase}")}.
    inject(0) {|mask, flag| mask | flag}
end