Module: Ronin::Installation

Defined in:
lib/ronin/installation.rb

Overview

The Installation module provides methods which help reflect on the installation of Ronin on the system.

Class Method Summary collapse

Class Method Details

.each_file(pattern) {|file| ... } ⇒ Enumerator

Enumerates over all files within a given directory found in any of the installed Ronin libraries.

Parameters:

  • directory (String)

    The directory path to search within.

Yields:

  • (file)

    The given block will be passed each file found within the directory.

Yield Parameters:

  • file (String)

    The sub-path to the file found within the directory.

Returns:

  • (Enumerator)

    Returns an Enumerator if no block is given.

Since:

  • 1.0.0



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ronin/installation.rb', line 96

def Installation.each_file(pattern)
  return enum_for(:each_file,pattern) unless block_given?

  # query the installed gems
  paths.each do |gem_path|
    slice_index = gem_path.length + 1

    Dir.glob(File.join(gem_path,pattern)) do |path|
      yield path[slice_index..-1]
    end
  end

  return nil
end

.each_file_in(directory, ext = nil) {|name| ... } ⇒ Enumerator

Enumerates over every file in a directory.

Parameters:

  • directory (String)

    The directory to search within.

  • ext (String, Symbol) (defaults to: nil)

    The optional file extension to search for.

Yields:

  • (name)

    The given block will be passed each matching file-name.

Yield Parameters:

  • name (String)

    The basename of the matching path within the directory.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.

Since:

  • 1.0.0



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ronin/installation.rb', line 133

def Installation.each_file_in(directory,ext=nil)
  return enum_for(:each_file_in,directory,ext) unless block_given?

  pattern = File.join(directory,'**','*')
  pattern << ".#{ext}" if ext

  slice_index = directory.length + 1

  each_file(pattern) do |path|
    yield path[slice_index..-1]
  end
end

.gemsHash{String => Gem::Specification}

Finds the installed Ronin libraries via RubyGems.

Returns:

  • (Hash{String => Gem::Specification})

    The names and gem-specs of the installed Ronin libraries.

Since:

  • 1.0.0



42
43
44
45
# File 'lib/ronin/installation.rb', line 42

def Installation.gems
  load! if @gems.empty?
  return @gems
end

.librariesArray<String>

The names of the additional Ronin libraries installed on the system.

Returns:

  • (Array<String>)

    The library names.

Since:

  • 1.0.0



72
73
74
# File 'lib/ronin/installation.rb', line 72

def Installation.libraries
  gems.keys
end

.load!true (protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds the installed Ronin libraries.

Returns:

  • (true)

    All Ronin libraries were successfully found.

Since:

  • 1.0.1



219
220
221
222
223
224
225
# File 'lib/ronin/installation.rb', line 219

def Installation.load!
  if Gem.loaded_specs.has_key?('ronin')
    load_gems!
  else
    load_gemspecs!
  end
end

.load_gems!true (protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds the installed Ronin gems.

Returns:

  • (true)

    All Ronin libraries were successfully found.

Since:

  • 1.0.1



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/ronin/installation.rb', line 158

def Installation.load_gems!
  register_gem = lambda { |gem|
    @gems[gem.name] = gem
    @paths << gem.full_gem_path
  }

  ronin_gem = Gem.loaded_specs['ronin']

  # add the main ronin gem
  register_gem[ronin_gem]

  # add any dependent gems
  ronin_gem.dependent_gems.each do |gems|
    register_gem[gems[0]]
  end

  return true
end

.load_gemspecs!true (protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Loads the gemspecs of Ronin libraries from the $LOAD_PATH.

Returns:

  • (true)

    All Ronin gemspecs were successfully found.

Since:

  • 1.0.0



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/ronin/installation.rb', line 187

def Installation.load_gemspecs!
  $LOAD_PATH.each do |lib_dir|
    root_dir = File.expand_path(File.join(lib_dir,'..'))
    gemspec_path = Dir[File.join(root_dir,'ronin*.gemspec')][0]

    if gemspec_path
      # switch into the gem directory, before loading the gemspec
      gem = Dir.chdir(root_dir) do
        Gem::Specification.load(gemspec_path)
      end

      # do not add duplicate ronin gems
      unless @gems.has_key?(gem.name)
        @gems[gem.name] = gem
        @paths << root_dir
      end
    end
  end

  return true
end

.pathsSet<String>

The paths of the installed Ronin libraries.

Returns:

  • (Set<String>)

    The paths of the Ronin libraries.

Since:

  • 1.0.1



57
58
59
60
# File 'lib/ronin/installation.rb', line 57

def Installation.paths
  load! if @paths.empty?
  return @paths
end