Class: FFI::Extractor::PluginList

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi/extractor/plugin_list.rb

Overview

Represents the list of loaded extractor plugins.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr = FFI::Pointer.new(0)) ⇒ PluginList

Initializes the plugin list.

Parameters:

  • ptr (FFI::Pointer) (defaults to: FFI::Pointer.new(0))

    The pointer to the list.



36
37
38
# File 'lib/ffi/extractor/plugin_list.rb', line 36

def initialize(ptr=FFI::Pointer.new(0))
  @ptr = ptr
end

Class Method Details

.default(policy = :default) ⇒ PluginList

Loads the installed extractor plugins.

Parameters:

  • policy (Symbol) (defaults to: :default)

    The policy for how the plugins will be ran.

Returns:

Raises:

  • (LoadError)

    The no plugins were loaded.



62
63
64
65
66
67
68
69
70
# File 'lib/ffi/extractor/plugin_list.rb', line 62

def self.default(policy=:default)
  ptr = Extractor.EXTRACTOR_plugin_add_defaults(policy)

  if ptr.null?
    raise(LoadError,"no plugins were loaded")
  end

  return new(ptr)
end

.release(ptr) ⇒ Object

Releases the plugin list.

Parameters:

  • ptr (FFI::Pointer)

    The pointer to the list.



46
47
48
# File 'lib/ffi/extractor/plugin_list.rb', line 46

def self.release(ptr)
  Extractor.EXTRACTOR_plugin_remove_all(ptr)
end

Instance Method Details

#add(name, options = '', policy = :default) ⇒ PluginList

Loads a plugin and adds it to the list.

Parameters:

  • name (Symbol)

    The plugin name.

  • options (String) (defaults to: '')

    Options for the plugin.

  • policy (Symbol) (defaults to: :default)

    The policy for how the plugin will be ran.

Returns:

Raises:

  • (LoadError)

    The plugin could not be loaded.



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ffi/extractor/plugin_list.rb', line 90

def add(name,options='',policy=:default)
  name    = name.to_s
  new_ptr = Extractor.EXTRACTOR_plugin_add(@ptr,name,options,policy)

  if new_ptr == @ptr
    raise(LoadError,"could not add #{name.dump} to the plugin list")
  end

  @ptr = new_ptr
  return self
end

#remove(name) ⇒ PluginList Also known as: delete

Removes a plugin from the list.

Parameters:

  • name (Symbol)

    The plugin name.

Returns:

Raises:

  • (ArgumentError)

    The plugin could not be found in the list.



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ffi/extractor/plugin_list.rb', line 114

def remove(name)
  name    = name.to_s
  new_ptr = Extractor.EXTRACTOR_plugin_remove(@ptr,name)

  if new_ptr == @ptr
    raise(ArgumentError,"could not remove #{name.dump} from the plugin list")
  end

  @ptr = new_ptr
  return self
end

#remove_allPluginList Also known as: clear

Removes all plugins from the list.

Returns:



134
135
136
137
# File 'lib/ffi/extractor/plugin_list.rb', line 134

def remove_all
  Extractor.EXTRACTOR_plugin_remove_all(@ptr)
  return self
end

#to_ptrFFI::Pointer

Converts the plugin list to a pointer.

Returns:

  • (FFI::Pointer)

    The pointer to the plugin list.



147
148
149
# File 'lib/ffi/extractor/plugin_list.rb', line 147

def to_ptr
  @ptr
end