sorbet/rbi/gems/rb-inotify@0.11.1.rbi
# typed: true
# DO NOT EDIT MANUALLY
# This is an autogenerated file for types exported from the `rb-inotify` gem.
# Please instead update this file by running `bin/tapioca gem rb-inotify`.
# The root module of the library, which is laid out as so:
#
# * {Notifier} -- The main class, where the notifications are set up
# * {Watcher} -- A watcher for a single file or directory
# * {Event} -- An filesystem event notification
#
# source://rb-inotify//lib/rb-inotify/version.rb#22
module INotify; end
# An event caused by a change on the filesystem.
# Each {Watcher} can fire many events,
# which are passed to that watcher's callback.
#
# source://rb-inotify//lib/rb-inotify/event.rb#5
class INotify::Event
# Creates an event from a string of binary data.
# Differs from {Event.consume} in that it doesn't modify the string.
#
# @param data [String] The data string
# @param notifier [Notifier] The {Notifier} that fired the event
# @private
# @raise [QueueOverflowError]
# @return [Event] a new instance of Event
#
# source://rb-inotify//lib/rb-inotify/event.rb#111
def initialize(data, notifier); end
# The absolute path of the file that the event occurred on.
#
# This is actually only as absolute as the path passed to the {Watcher}
# that created this event.
# However, it is relative to the working directory,
# assuming that hasn't changed since the watcher started.
#
# @return [String]
#
# source://rb-inotify//lib/rb-inotify/event.rb#66
def absolute_name; end
# Calls the callback of the watcher that fired this event,
# passing in the event itself.
#
# @private
#
# source://rb-inotify//lib/rb-inotify/event.rb#127
def callback!; end
# An integer specifying that this event is related to some other event,
# which will have the same cookie.
#
# Currently, this is only used for files that are moved within the same directory.
# Both the `:moved_from` and the `:moved_to` events will have the same cookie.
#
# @private
# @return [Fixnum]
#
# source://rb-inotify//lib/rb-inotify/event.rb#43
def cookie; end
# Returns the flags that describe this event.
# This is generally similar to the input to {Notifier#watch},
# except that it won't contain options flags nor `:all_events`,
# and it may contain one or more of the following flags:
#
# `:unmount`
# : The filesystem containing the watched file or directory was unmounted.
#
# `:ignored`
# : The \{#watcher watcher} was closed, or the watched file or directory was deleted.
#
# `:isdir`
# : The subject of this event is a directory.
#
# @return [Array<Symbol>]
#
# source://rb-inotify//lib/rb-inotify/event.rb#86
def flags; end
# The name of the file that the event occurred on.
# This is only set for events that occur on files in directories;
# otherwise, it's `""`.
# Similarly, if the event is being fired for the directory itself
# the name will be `""`
#
# This pathname is relative to the enclosing directory.
# For the absolute pathname, use \{#absolute\_name}.
# Note that when the `:recursive` flag is passed to {Notifier#watch},
# events in nested subdirectories will still have a `#name` field
# relative to their immediately enclosing directory.
# For example, an event on the file `"foo/bar/baz"`
# will have name `"baz"`.
#
# @return [String]
#
# source://rb-inotify//lib/rb-inotify/event.rb#28
def name; end
# The {Notifier} that fired this event.
#
# @return [Notifier]
#
# source://rb-inotify//lib/rb-inotify/event.rb#33
def notifier; end
# A list of other events that are related to this one.
# Currently, this is only used for files that are moved within the same directory:
# the `:moved_from` and the `:moved_to` events will be related.
#
# @return [Array<Event>]
#
# source://rb-inotify//lib/rb-inotify/event.rb#11
def related; end
# Returns the size of this event object in bytes,
# including the \{#name} string.
#
# @return [Fixnum]
#
# source://rb-inotify//lib/rb-inotify/event.rb#135
def size; end
# Returns the {Watcher} that fired this event.
#
# @return [Watcher]
#
# source://rb-inotify//lib/rb-inotify/event.rb#54
def watcher; end
# The {Watcher#id id} of the {Watcher} that fired this event.
#
# @private
# @return [Fixnum]
#
# source://rb-inotify//lib/rb-inotify/event.rb#49
def watcher_id; end
private
# source://rb-inotify//lib/rb-inotify/event.rb#141
def fix_encoding(name); end
class << self
# Constructs an {Event} object from a string of binary data,
# and destructively modifies the string to get rid of the initial segment
# used to construct the Event.
#
# @param data [String] The string to be modified
# @param notifier [Notifier] The {Notifier} that fired the event
# @private
# @return [Event, nil] The event, or `nil` if the string is empty
#
# source://rb-inotify//lib/rb-inotify/event.rb#98
def consume(data, notifier); end
end
end
# This module contains the low-level foreign-function interface code
# for dealing with the inotify C APIs.
# It's an implementation detail, and not meant for users to deal with.
#
# @private
#
# source://rb-inotify//lib/rb-inotify/native.rb#9
module INotify::Native
extend ::FFI::Library
def fpathconf(*_arg0); end
def inotify_add_watch(*_arg0); end
def inotify_init(*_arg0); end
def inotify_rm_watch(*_arg0); end
class << self
def fpathconf(*_arg0); end
def inotify_add_watch(*_arg0); end
def inotify_init(*_arg0); end
def inotify_rm_watch(*_arg0); end
end
end
# The C struct describing an inotify event.
#
# @private
#
# source://rb-inotify//lib/rb-inotify/native.rb#20
class INotify::Native::Event < ::FFI::Struct; end
# A module containing all the inotify flags
# to be passed to {Notifier#watch}.
#
# @private
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#7
module INotify::Native::Flags
class << self
# Converts a bitmask from the C API into a list of flags.
#
# @param mask [Fixnum]
# @return [Array<Symbol>]
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#86
def from_mask(mask); end
# Converts a list of flags to the bitmask that the C API expects.
#
# @param flags [Array<Symbol>]
# @return [Fixnum]
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#77
def to_mask(flags); end
end
end
# File was accessed.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#9
INotify::Native::Flags::IN_ACCESS = T.let(T.unsafe(nil), Integer)
# All events which a program can wait on.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#40
INotify::Native::Flags::IN_ALL_EVENTS = T.let(T.unsafe(nil), Integer)
# Metadata changed.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#11
INotify::Native::Flags::IN_ATTRIB = T.let(T.unsafe(nil), Integer)
# Close.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#36
INotify::Native::Flags::IN_CLOSE = T.let(T.unsafe(nil), Integer)
# Unwrittable file closed.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#17
INotify::Native::Flags::IN_CLOSE_NOWRITE = T.let(T.unsafe(nil), Integer)
# Writtable file was closed.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#13
INotify::Native::Flags::IN_CLOSE_WRITE = T.let(T.unsafe(nil), Integer)
# Subfile was created.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#25
INotify::Native::Flags::IN_CREATE = T.let(T.unsafe(nil), Integer)
# Subfile was deleted.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#27
INotify::Native::Flags::IN_DELETE = T.let(T.unsafe(nil), Integer)
# Self was deleted.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#29
INotify::Native::Flags::IN_DELETE_SELF = T.let(T.unsafe(nil), Integer)
# Do not follow a sym link.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#50
INotify::Native::Flags::IN_DONT_FOLLOW = T.let(T.unsafe(nil), Integer)
# File was ignored.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#64
INotify::Native::Flags::IN_IGNORED = T.let(T.unsafe(nil), Integer)
# Event occurred against dir.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#66
INotify::Native::Flags::IN_ISDIR = T.let(T.unsafe(nil), Integer)
# Add to the mask of an already existing watch.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#52
INotify::Native::Flags::IN_MASK_ADD = T.let(T.unsafe(nil), Integer)
# File was modified.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#15
INotify::Native::Flags::IN_MODIFY = T.let(T.unsafe(nil), Integer)
# Moves.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#38
INotify::Native::Flags::IN_MOVE = T.let(T.unsafe(nil), Integer)
# File was moved from X.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#21
INotify::Native::Flags::IN_MOVED_FROM = T.let(T.unsafe(nil), Integer)
# File was moved to Y.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#23
INotify::Native::Flags::IN_MOVED_TO = T.let(T.unsafe(nil), Integer)
# Self was moved.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#31
INotify::Native::Flags::IN_MOVE_SELF = T.let(T.unsafe(nil), Integer)
# Only send event once.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#54
INotify::Native::Flags::IN_ONESHOT = T.let(T.unsafe(nil), Integer)
# Only watch the path if it is a directory.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#48
INotify::Native::Flags::IN_ONLYDIR = T.let(T.unsafe(nil), Integer)
# File was opened.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#19
INotify::Native::Flags::IN_OPEN = T.let(T.unsafe(nil), Integer)
# Event queued overflowed.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#62
INotify::Native::Flags::IN_Q_OVERFLOW = T.let(T.unsafe(nil), Integer)
# Backing fs was unmounted.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#60
INotify::Native::Flags::IN_UNMOUNT = T.let(T.unsafe(nil), Integer)
# returns the maximum length of a filename in the directory path or fd that the process is allowed to create. The corresponding macro is _POSIX_NAME_MAX.
#
# source://rb-inotify//lib/rb-inotify/native/flags.rb#71
INotify::Native::Flags::PC_NAME_MAX = T.let(T.unsafe(nil), Integer)
# Notifier wraps a single instance of inotify.
# It's possible to have more than one instance,
# but usually unnecessary.
#
# @example
# # Create the notifier
# notifier = INotify::Notifier.new
#
# # Run this callback whenever the file path/to/foo.txt is read
# notifier.watch("path/to/foo.txt", :access) do
# puts "Foo.txt was accessed!"
# end
#
# # Watch for any file in the directory being deleted
# # or moved out of the directory.
# notifier.watch("path/to/directory", :delete, :moved_from) do |event|
# # The #name field of the event object contains the name of the affected file
# puts "#{event.name} is no longer in the directory!"
# end
#
# # Nothing happens until you run the notifier!
# notifier.run
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#26
class INotify::Notifier
# Creates a new {Notifier}.
#
# @raise [SystemCallError] if inotify failed to initialize for some reason
# @return [Notifier]
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#49
def initialize; end
# Close the notifier.
#
# @raise [SystemCallError] if closing the underlying file descriptor fails.
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#268
def close; end
# The underlying file descriptor for this notifier.
# This is a valid OS file descriptor, and can be used as such
# (except under JRuby -- see \{#to\_io}).
#
# @return [Fixnum]
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#41
def fd; end
# Blocks until there are one or more filesystem events
# that this notifier has watchers registered for.
# Once there are events, the appropriate callbacks are called
# and this function returns.
#
# @see #run
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#258
def process; end
# Blocks until there are one or more filesystem events that this notifier
# has watchers registered for. Once there are events, returns their {Event}
# objects.
#
# This can return an empty list if the watcher was closed elsewhere.
#
# {#run} or {#process} are ususally preferable to calling this directly.
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#281
def read_events; end
# Starts the notifier watching for filesystem events.
# Blocks until \{#stop} is called.
#
# @see #process
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#227
def run; end
# Stop watching for filesystem events.
# That is, if we're in a \{#run} loop,
# exit out as soon as we finish handling the events.
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#241
def stop; end
# Returns a Ruby IO object wrapping the underlying file descriptor.
# Since this file descriptor is fully functional (except under JRuby),
# this IO object can be used in any way a Ruby-created IO object can.
# This includes passing it to functions like `#select`.
#
# Note that this always returns the same IO object.
# Creating lots of IO objects for the same file descriptor
# can cause some odd problems.
#
# **This is not supported under JRuby**.
# JRuby currently doesn't use native file descriptors for the IO object,
# so we can't use this file descriptor as a stand-in.
#
# @raise [NotImplementedError] if this is being called in JRuby
# @return [IO] An IO object wrapping the file descriptor
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#94
def to_io; end
# Watches a file or directory for changes,
# calling the callback when there are.
# This is only activated once \{#process} or \{#run} is called.
#
# **Note that by default, this does not recursively watch subdirectories
# of the watched directory**.
# To do so, use the `:recursive` flag.
#
# ## Flags
#
# `:access`
# : A file is accessed (that is, read).
#
# `:attrib`
# : A file's metadata is changed (e.g. permissions, timestamps, etc).
#
# `:close_write`
# : A file that was opened for writing is closed.
#
# `:close_nowrite`
# : A file that was not opened for writing is closed.
#
# `:modify`
# : A file is modified.
#
# `:open`
# : A file is opened.
#
# ### Directory-Specific Flags
#
# These flags only apply when a directory is being watched.
#
# `:moved_from`
# : A file is moved out of the watched directory.
#
# `:moved_to`
# : A file is moved into the watched directory.
#
# `:create`
# : A file is created in the watched directory.
#
# `:delete`
# : A file is deleted in the watched directory.
#
# `:delete_self`
# : The watched file or directory itself is deleted.
#
# `:move_self`
# : The watched file or directory itself is moved.
#
# ### Helper Flags
#
# These flags are just combinations of the flags above.
#
# `:close`
# : Either `:close_write` or `:close_nowrite` is activated.
#
# `:move`
# : Either `:moved_from` or `:moved_to` is activated.
#
# `:all_events`
# : Any event above is activated.
#
# ### Options Flags
#
# These flags don't actually specify events.
# Instead, they specify options for the watcher.
#
# `:onlydir`
# : Only watch the path if it's a directory.
#
# `:dont_follow`
# : Don't follow symlinks.
#
# `:mask_add`
# : Add these flags to the pre-existing flags for this path.
#
# `:oneshot`
# : Only send the event once, then shut down the watcher.
#
# `:recursive`
# : Recursively watch any subdirectories that are created.
# Note that this is a feature of rb-inotify,
# rather than of inotify itself, which can only watch one level of a directory.
# This means that the {Event#name} field
# will contain only the basename of the modified file.
# When using `:recursive`, {Event#absolute_name} should always be used.
#
# @param path [String] The path to the file or directory
# @param flags [Array<Symbol>] Which events to watch for
# @raise [SystemCallError] if the file or directory can't be watched,
# e.g. if the file isn't found, read access is denied,
# or the flags don't contain any events
# @return [Watcher] A Watcher set up to watch this path for these events
# @yield [event] A block that will be called
# whenever one of the specified events occur
# @yieldparam event [Event] The Event object containing information
# about the event that occured
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#196
def watch(path, *flags, &callback); end
# A hash from {Watcher} ids to the instances themselves.
#
# @private
# @return [{Fixnum => Watcher}]
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#34
def watchers; end
private
# Same as IO#readpartial, or as close as we need.
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#312
def readpartial(size); end
end
# * Files in `/dev/fd` sometimes register as directories, but are not enumerable.
#
# source://rb-inotify//lib/rb-inotify/notifier.rb#28
INotify::Notifier::NON_RECURSIVE = T.let(T.unsafe(nil), String)
# source://rb-inotify//lib/rb-inotify/errors.rb#2
class INotify::QueueOverflowError < ::RuntimeError; end
# source://rb-inotify//lib/rb-inotify/version.rb#23
INotify::VERSION = T.let(T.unsafe(nil), String)
# Watchers monitor a single path for changes,
# specified by {INotify::Notifier#watch event flags}.
# A watcher is usually created via \{Notifier#watch}.
#
# One {Notifier} may have many {Watcher}s.
# The Notifier actually takes care of the checking for events,
# via \{Notifier#run #run} or \{Notifier#process #process}.
# The main purpose of having Watcher objects
# is to be able to disable them using \{#close}.
#
# source://rb-inotify//lib/rb-inotify/watcher.rb#11
class INotify::Watcher
# Creates a new {Watcher}.
#
# @private
# @raise [SystemCallError]
# @return [Watcher] a new instance of Watcher
# @see Notifier#watch
#
# source://rb-inotify//lib/rb-inotify/watcher.rb#61
def initialize(notifier, path, *flags, &callback); end
# Calls this Watcher's callback with the given {Event}.
#
# @param event [Event]
# @private
#
# source://rb-inotify//lib/rb-inotify/watcher.rb#40
def callback!(event); end
# Disables this Watcher, so that it doesn't fire any more events.
#
# @raise [SystemCallError] if the watch fails to be disabled for some reason
#
# source://rb-inotify//lib/rb-inotify/watcher.rb#47
def close; end
# The {INotify::Notifier#watch flags}
# specifying the events that this Watcher is watching for,
# and potentially some options as well.
#
# @return [Array<Symbol>]
#
# source://rb-inotify//lib/rb-inotify/watcher.rb#27
def flags; end
# The id for this Watcher.
# Used to retrieve this Watcher from {Notifier#watchers}.
#
# @private
# @return [Fixnum]
#
# source://rb-inotify//lib/rb-inotify/watcher.rb#34
def id; end
# The {Notifier} that this Watcher belongs to.
#
# @return [Notifier]
#
# source://rb-inotify//lib/rb-inotify/watcher.rb#15
def notifier; end
# The path that this Watcher is watching.
#
# @return [String]
#
# source://rb-inotify//lib/rb-inotify/watcher.rb#20
def path; end
end