Class: Whereis

Inherits:
Object
  • Object
show all
Defined in:
lib/unix/whereis.rb

Overview

UNIX whereis command frontend.

See Also:

Constant Summary collapse

TYPES =

Target types to arguments conversion table.

{
    :binary => :b,
    :manual => :m,
    :source => :s,
    :unusual => :u,
}
PATHS =

Target type path settings to arguments conversion table.

{
    :binary => :B,
    :manual => :M,
    :source => :S,
}

Class Method Summary collapse

Class Method Details

.available?(name, type = :binary) ⇒ Boolean

Indicates, file of the target type is available.

Returns:

  • (Boolean)


167
168
169
# File 'lib/unix/whereis.rb', line 167

def self.available?(name, type = :binary)
    self.file?(name, type).length > 0
end

.binary?(name, options = nil) ⇒ Array .binary?(name, options = { }) ⇒ Array

Checks where is some binary file. By default uses default whereis options.

Overloads:

  • .binary?(name, options = nil) ⇒ Array

    Checks according to name and :unusual settings.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (:unusual, nil) (defaults to: nil)

      eventuall :unusual settings

    Returns:

    • (Array)

      list of found locations

  • .binary?(name, options = { }) ⇒ Array

    Checks according to name and additionaů options.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (Hash) (defaults to: { })

      options

    Options Hash (options):

    • :path (String)

      path to binary folder

    • :unusual (Boolean)

      true it it’s set, false in otherwise

    Returns:

    • (Array)

      list of found locations

Returns:

  • (Array)

    list of found locations



111
112
113
# File 'lib/unix/whereis.rb', line 111

def self.binary?(name, options = nil)
    __get(name, :binary, options)
end

.file?(name, options = nil) ⇒ Array .file?(name, options = [ ]) ⇒ Array .file?(name, options = { }) ⇒ Array

Checks where is some file. By default uses default whereis options.

Overloads:

  • .file?(name, options = nil) ⇒ Array

    Checks according to file name and single type specification. Can be replaced by specialized methods of the module which use it. Type specification can be :binary, :manual or :source.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (Symbol) (defaults to: nil)

      type of the file

    Returns:

    • (Array)

      list of found locations

  • .file?(name, options = [ ]) ⇒ Array

    Allows define multiple types for checking with eventual addition of the whereis “unusual” setting.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (Array) (defaults to: [ ])

      array of type of the files and eventually the :unusual specification

    Returns:

    • (Array)

      list of found locations

    See Also:

  • .file?(name, options = { }) ⇒ Array

    Allows define paths for each type and eventually the unusual settings too.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (Hash) (defaults to: { })

      path specifications and/or :unusual setting (see below)

    Options Hash (options):

    • :binary (String)

      path to binaries folder

    • :manual (String)

      path to manual pages folder

    • :source (String)

      path to sources folder

    • :unusual (Boolean)

      true for set the “unusual” flag

    Returns:

    • (Array)

      list of found locations

    See Also:

Returns:

  • (Array)

    list of found locations



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/unix/whereis.rb', line 71

def self.file?(name, options = [ ])

    # Parses arguments
    cmd = CommandBuilder::new(:whereis)
 
    if options.symbol?
        __add_type(cmd, options)
    elsif options.array?
        options.each { |i| __add_type(cmd, i) }
    elsif options.hash?
        options.each_pair { |n, v| __add_path(cmd, n, v) }
    end
    
    cmd << name.to_s
    
    # Parses output
    output = cmd.execute[(name.to_s.length + 2)..-1]
    return output.split(" ")
end

.manual?(name, options = nil) ⇒ Array .manual?(name, options = { }) ⇒ Array

Checks where is some manual page file. By default uses default whereis options.

Overloads:

  • .manual?(name, options = nil) ⇒ Array

    Checks according to name and :unusual settings.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (:unusual, nil) (defaults to: nil)

      eventuall :unusual settings

    Returns:

    • (Array)

      list of found locations

  • .manual?(name, options = { }) ⇒ Array

    Checks according to name and additionaů options.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (Hash) (defaults to: { })

      options

    Options Hash (options):

    • :path (String)

      path to manual pages folder

    • :unusual (Boolean)

      true it it’s set, false in otherwise

    Returns:

    • (Array)

      list of found locations

Returns:

  • (Array)

    list of found locations



135
136
137
# File 'lib/unix/whereis.rb', line 135

def self.manual?(name, options = nil)
    __get(name, :manual, options)
end

.source?(name, options = nil) ⇒ Array .source?(name, options = { }) ⇒ Array

Checks where is some source file. By default uses default whereis options.

Overloads:

  • .source?(name, options = nil) ⇒ Array

    Checks according to name and :unusual settings.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (:unusual, nil) (defaults to: nil)

      eventuall :unusual settings

    Returns:

    • (Array)

      list of found locations

  • .source?(name, options = { }) ⇒ Array

    Checks according to name and additionaů options.

    Parameters:

    • name (String)

      name or wildcard of the file

    • options (Hash) (defaults to: { })

      options

    Options Hash (options):

    • :path (String)

      path to source folder

    • :unusual (Boolean)

      true it it’s set, false in otherwise

    Returns:

    • (Array)

      list of found locations

Returns:

  • (Array)

    list of found locations



159
160
161
# File 'lib/unix/whereis.rb', line 159

def self.source?(name, options = nil)
    __get(name, :source, options)
end