Class: TDriver::PluginService

Inherits:
Object
  • Object
show all
Defined in:
lib/tdriver/util/plugin/service.rb

Class Method Summary collapse

Class Method Details

.call_plugin_method(plugin_name, method_name, *args) ⇒ Object

TODO: document me



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/tdriver/util/plugin/service.rb', line 263

def self.call_plugin_method( plugin_name, method_name, *args )

  begin

    @registered_plugins.fetch( plugin_name ){

      # in case if plugin not found from registered plugins list
      raise ArgumentError, "No such plugin registered #{ plugin_name }"

    }[ :plugin_module ].send( method_name.to_sym, *args )

  rescue ArgumentError

    # raise argument errors as is
    raise      

  rescue 

    # raise all other exceptions as PluginError
    raise MobyUtil::PluginError, "Error occured during calling #{ method_name } method for #{ plugin_name } (#{ $!.class }: #{ $!.message })"

  end

end

.disable_plugin(plugin_name) ⇒ Object

TODO: document me



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/tdriver/util/plugin/service.rb', line 157

def self.disable_plugin( plugin_name )

  begin

    # disable plugin
    @registered_plugins[ plugin_name ][ :enabled ] = false

    # remove name from enabled plugins list
    #@enabled_plugins.delete( plugin_name )

    update_enabled_plugins_list

  rescue 

    raise ArgumentError, "No such plugin registered #{ plugin_name }"

  end
  
end

.enable_plugin(plugin_name) ⇒ Object

TODO: document me



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/tdriver/util/plugin/service.rb', line 136

def self.enable_plugin( plugin_name )
  
  begin

    # enable plugin
    @registered_plugins[ plugin_name ][ :enabled ] = true

    # add name to enabled plugins list
    #@enabled_plugins << plugin_name unless @enabled_plugins.include?( plugin_name )

    update_enabled_plugins_list

  rescue 

    raise ArgumentError, "No such plugin registered #{ plugin_name }"

  end

end

.enabled_pluginsObject

TODO: document me



129
130
131
132
133
# File 'lib/tdriver/util/plugin/service.rb', line 129

def self.enabled_plugins

  @enabled_plugins

end

.load_plugin(plugin_name) ⇒ Object

TODO: document me



247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/tdriver/util/plugin/service.rb', line 247

def self.load_plugin( plugin_name )

  begin

    # load plugin implementation
    require plugin_name 

  rescue LoadError

    raise RuntimeError, "Error while loading plugin #{ plugin_name.to_s }. Please verify that the plugin is installed properly (#{ $!.class }: #{ $!.message })"

  end

end

.plugin_enabled?(plugin_name) ⇒ Boolean

TODO: document me

Returns:

  • (Boolean)


178
179
180
181
182
# File 'lib/tdriver/util/plugin/service.rb', line 178

def self.plugin_enabled?( plugin_name )

  @enabled_plugins.include?( plugin_name )
  
end

.plugin_registered?(plugin_name, type = nil) ⇒ Boolean

returns true if plugin is registered, plugin type can be given as optional parameter

Returns:

  • (Boolean)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/tdriver/util/plugin/service.rb', line 102

def self.plugin_registered?( plugin_name, type = nil )

  # check if given plugin is registered
  if @registered_plugins.has_key?( plugin_name )
  
    unless type.nil?
    
      # plugin registered, compare that given plugin type matches
      @registered_plugins[ plugin_name ][ :type ] == type
            
    else
    
      # plugin registered, no specific plugin type given 
      true
    
    end
  
  else
  
    # plugin not registered, not found from registered_plugins list
    false
  
  end

end

.register_plugin(plugin_module) ⇒ Object

TODO: document me

Raises:

  • (ArgumentError)


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/tdriver/util/plugin/service.rb', line 185

def self.register_plugin( plugin_module )
 
  # retrieve plugin name 
  plugin_name = plugin_data_value( plugin_module, :plugin_name )

  # throw exception if plugin is already registered
  raise ArgumentError, "Plugin #{ plugin_name } is already registered" if @registered_plugins.has_key?( plugin_name )

  # plugin configuration
  @registered_plugins[ plugin_name ] = {
 
    # store plugin type
    :type => plugin_data_value( plugin_module, :plugin_type ), 

    # store plugin implementation module name
    :plugin_module => plugin_module, 

    # set plugin to enabled state
    :enabled => true 

  }
  
  @plugin_order << plugin_name

  # register plugin
  plugin_module.register_plugin

  # add name to enabled plugins list
  #@enabled_plugins << plugin_name unless @enabled_plugins.include?( plugin_name )

  update_enabled_plugins_list

end

.registered_plugins(type = nil) ⇒ Object

TODO: document me



94
95
96
97
98
99
# File 'lib/tdriver/util/plugin/service.rb', line 94

def self.registered_plugins( type = nil )

  # return all or plugins of given type
  Hash[ @registered_plugins.select{ | key, value | type.nil? || value[ :type ] == type } ]

end

.unregister_plugin(plugin_name) ⇒ Object

TODO: document me



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/tdriver/util/plugin/service.rb', line 220

def self.unregister_plugin( plugin_name )

  begin

    # call plugin unregister mechanism
    @registered_plugins[ plugin_name ][ :plugin_module ].unregister_plugin

    # remove from the plugins hash
    @registered_plugins.delete( plugin_name )

    # remove from the plugins hash
    @enabled_plugins.delete( plugin_name )

    update_enabled_plugins_list

    # remove from plugins list (registration order)
    @plugin_order.delete( plugin_name )

  rescue

    raise ArgumentError, "Failed to unregister plugin due to plugin #{ plugin_name.inspect } is not registered"

  end

end