Class: Ronin::Platform::Extension

Included Modules

Contextify, Ronin::Static::Finders, Ronin::UI::Output::Helpers

Attributes

Instance Attributes

name [R] public

Name of extension.

paths [R] public

Paths of similar extensions.

Constants

EXTENSION_FILE
'extension.rb'
LIB_DIR
'lib'
STATIC_DIR
'static'

Constructor Summary

public initialize(name, &block)

Creates a new Extension object.

Meta Tags

Examples

  Extension.new('exploits')
  Extension.new('awesome') do |ext|
    # ...
  end

Parameters:

[String] name

The name to give the newly created Extension object.

Yields:

[Object]
The block that will be instance-evaled inside the newly created Extension object.
[View source]


81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ronin/platform/extension.rb', line 81

def initialize(name,&block)
  @name = name.to_s
  @paths = []

  @setup = false
  @toredown = true

  @setup_blocks = []
  @teardown_blocks = []

  instance_eval(&block) if block
end

Public Visibility

Public Instance Method Summary

#exposed_methods

Returns: Array

#has_method?(name)

Searches for a public method with the specified name.

Returns: Boolean

#include(name, &block) {|ext| ... }

Includes all extensions with the matching name into the extension.

Returns: Extension

#include_path(path, &block) {|ext| ... }

Includes the extension at the specified path into the extension.

Returns: Extension

#run(&block) {|ext| ... }

Sets up the extension, passes the extension to the specified.

Returns: Extension

#setup!(&block) {|ext| ... }

Calls the setup blocks of the extension.

Returns: Extension

#setup?

Returns: Boolean

#static_paths(path, &block)
#teardown!(&block) {|ext| ... }

Run the teardown blocks of the extension.

Returns: Extension

#tmp_dir

The temporary directory for the extension.

Returns: String

#to_s

Returns: String

#toredown?

Returns: Boolean

Public Instance Method Details

exposed_methods

public Array exposed_methods

Meta Tags

Returns:

[Array]

The list of public methods exposed by the extension.

[View source]


166
167
168
# File 'lib/ronin/platform/extension.rb', line 166

def exposed_methods
  methods(false).map { |name| name.to_sym }
end

has_method?

public Boolean has_method?(name)

Searches for a public method with the specified name.

Meta Tags

Example:

  ext.has_method?(:console)
  # => true

Parameters:

[Symbol, String] name

The method name to search for.

Returns:

[Boolean]

Specifies whether there is a public method with the specified name.

[View source]


184
185
186
# File 'lib/ronin/platform/extension.rb', line 184

def has_method?(name)
  exposed_methods.include?(name.to_sym)
end

include

public Extension include(name, &block) {|ext| ... }

Includes all extensions with the matching name into the extension.

Meta Tags

Parameters:

[String] name

The name of the extensions to include.

Yields:

[ext]

If a block is given, it will be passed the extension, after the other extensions have been included into it.

Yield Parameters:

[Extension] ext

The extension.

Returns:

[Extension]

The extension.

[View source]


110
111
112
113
114
115
116
117
# File 'lib/ronin/platform/extension.rb', line 110

def include(name,&block)
  Platform.overlays.extension_paths(name).each do |path|
    include_path(path)
  end

  block.call(self) if block
  return self
end

include_path

public Extension include_path(path, &block) {|ext| ... }

Includes the extension at the specified path into the extension.

Meta Tags

Parameters:

[String] path

The path of the extension directory to include from.

Yields:

[ext]

If a block is given, it will be passed the extension.

Yield Parameters:

[Extension] ext

The extension.

Returns:

[Extension]

The extension.

Raises:

[ExtensionNotFound]

The specified path was not a valid directory.

[View source]


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/ronin/platform/extension.rb', line 137

def include_path(path,&block)
  path = File.expand_path(path)

  unless File.directory?(path)
    raise(ExtensionNotFound,"extension #{path.dump} is not a valid extension",caller)
  end

  # add to the search paths
  @paths << path

  extension_file = File.join(path,EXTENSION_FILE)

  if File.file?(extension_file)
    # instance_eval the extension block
    context_block = Extension.load_context_block(extension_file)

    if context_block
      catch_all { instance_eval(&context_block) }
    end
  end

  block.call(self) if block
  return self
end

run

public Extension run(&block) {|ext| ... }

Sets up the extension, passes the extension to the specified block and then tears down the extension.

Meta Tags

Example:

  ext.run do |ext|
    ext.console(ARGV)
  end

Yields:

[(ext)]

If a block is given, it will be called after the extension has been setup. When the block has finished, the extension will be toredown.

Yield Parameters:

[Extension] ext

The extension.

Returns:

[Extension]

The extension.

[View source]


297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/ronin/platform/extension.rb', line 297

def run(&block)
  setup!

  if block
    if block.arity == 1
      block.call(self)
    else
      block.call()
    end
  end

  teardown!
  return self
end

setup!

public Extension setup!(&block) {|ext| ... }

Calls the setup blocks of the extension.

Meta Tags

Examples

  ext.setup!
  # => #<Ronin::Platform::Extension: ...>
  ext.setup! do |ext|
    puts "Extension #{ext} has been setup..."
  end

Yields:

[ext]

If a block is given, it will be passed the extension, once it has been setup.

Yield Parameters:

[Extension] ext

The extension.

Returns:

[Extension]

The extension.

[View source]


210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/ronin/platform/extension.rb', line 210

def setup!(&block)
  unless @setup
    @setup_blocks.each do |setup_block|
      setup_block.call(self) if setup_block
    end

    @setup = true
    @toredown = false
  end

  block.call(self) if block
  return self
end

setup?

public Boolean setup?

Meta Tags

Returns:

[Boolean]

Specifies whether the extension has been setup.

[View source]


228
229
230
# File 'lib/ronin/platform/extension.rb', line 228

def setup?
  @setup == true
end

static_paths

public static_paths(path, &block)
[View source]


323
324
325
326
327
328
329
330
331
332
# File 'lib/ronin/platform/extension.rb', line 323

def static_paths(path,&block)
  @paths.each do |dir|
    static_dir = File.join(dir,STATIC_DIR)
    next unless File.directory?(static_dir)

    block.call(File.join(static_dir,path))
  end

  super(path,&block)
end

teardown!

public Extension teardown!(&block) {|ext| ... }

Run the teardown blocks of the extension.

Meta Tags

Examples

  ext.teardown!
  # => #<Ronin::Platform::Extension: ...>
  ext.teardown! do |ext|
    puts "Extension #{ext} is being tore down..."
  end

Yields:

[ext]

If a block is given, it will be passed the extension, before it has been toredown.

Yield Parameters:

[Extension] ext

The extension.

Returns:

[Extension]

The extension.

[View source]


254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/ronin/platform/extension.rb', line 254

def teardown!(&block)
  block.call(self) if block

  unless @toredown
    @teardown_blocks.each do |teardown_block|
      teardown_block.call(self) if teardown_block
    end

    @toredown = true
    @setup = false
  end

  return self
end

tmp_dir

public String tmp_dir

The temporary directory for the extension.

Meta Tags

Returns:

[String]

The path to the extensions temporary directory within Config::TMP_DIR.

[View source]


319
320
321
# File 'lib/ronin/platform/extension.rb', line 319

def tmp_dir
  @tmp_dir ||= Config.tmp_dir(@name)
end

to_s

public String to_s

Meta Tags

Returns:

[String]

The name of the extension.

[View source]


338
339
340
# File 'lib/ronin/platform/extension.rb', line 338

def to_s
  @name.to_s
end

toredown?

public Boolean toredown?

Meta Tags

Returns:

[Boolean]

Specifies whether the extension has been toredown.

[View source]


273
274
275
# File 'lib/ronin/platform/extension.rb', line 273

def toredown?
  @toredown == true
end

Protected Visibility

Protected Instance Method Summary

#attr_accessor(*names)

Defines reader and writer methods for the listed instance variables.

#attr_reader(*names)

Defines reader methods for the listed instance variables.

#attr_writer(*names)

Defines writer methods for the listed instance variables.

#setup(&block)

Adds the specified block to the list of blocks to run in order.

#teardown(&block)

Adds the specified block to the list of blocks to run in order.

Protected Instance Methods Included from Ronin::UI::Output::Helpers

print_debug, print_error, print_info, print_warning, puts

Protected Instance Method Details

attr_accessor

protected attr_accessor(*names)

Defines reader and writer methods for the listed instance variables.

Meta Tags

Example:

  attr_accessor :var1, :var2

  self.var1 = :foo
  self.var1
  # => :foo

Parameters:

[Array<Symbol, String>] names

The names of the instance variables to define reader and writer methods for.

See Also:

attr_reader, attr_writer
[View source]


411
412
413
414
# File 'lib/ronin/platform/extension.rb', line 411

def attr_accessor(*names)
  attr_reader(*names)
  attr_writer(*names)
end

attr_reader

protected attr_reader(*names)

Defines reader methods for the listed instance variables.

Meta Tags

Example:

  attr_reader :var1, :var2

  self.var1
  # => nil

Parameters:

[Array<Symbol, String>] names

The names of instance variables to add reader methods for.

[View source]


356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/ronin/platform/extension.rb', line 356

def attr_reader(*names)
  names.each do |name|
    name = name.to_sym
    ivar_name = "@#{name}"

    instance_eval %{
      def #{name}
        instance_variable_get(#{ivar_name.dump})
      end
    }
  end
end

attr_writer

protected attr_writer(*names)

Defines writer methods for the listed instance variables.

Meta Tags

Example:

  attr_writer :var1, :var2

  self.var1 = :foo
  self.var2 = :bar

Parameters:

[Array<Symbol, String>] names

The names of the instance variables to define writer methods for.

[View source]


381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/ronin/platform/extension.rb', line 381

def attr_writer(*names)
  names.each do |name|
    name = name.to_sym
    ivar_name = "@#{name}"

    instance_eval %{
      def #{name}=(value)
        instance_variable_set(#{ivar_name.dump},value)
      end
    }
  end
end

setup

protected setup(&block)

Adds the specified block to the list of blocks to run in order to properly setup the extension.

Meta Tags

Example:

  setup do
    @var = 'hello'
  end
[View source]


425
426
427
428
# File 'lib/ronin/platform/extension.rb', line 425

def setup(&block)
  @setup_blocks << block if block
  return self
end

teardown

protected teardown(&block)

Adds the specified block to the list of blocks to run in order to properly tear-down the extension.

Meta Tags

Example:

  teardown do
    @file.close
  end
[View source]


439
440
441
442
# File 'lib/ronin/platform/extension.rb', line 439

def teardown(&block)
  @teardown_blocks << block if block
  return self
end
Generated on Friday, September 25 2009 at 02:57:10 PM by YARD 0.2.3.5 (ruby-1.8.6).