module Retrospec::Plugins

Public Instance Methods

available_plugins() click to toggle source
# File lib/retrospec/plugins.rb, line 54
def available_plugins
   begin
     get_remote_data('https://raw.githubusercontent.com/nwops/retrospec/master/available_plugins.yaml')
   rescue SocketError
     puts "Using cached list of available plugins, use internet to get latest list."
     YAML.load_file(File.join(gem_dir, 'available_plugins.yaml'))
   end
end
discover_plugin(module_path) click to toggle source

returns the first plugin class that supports this module directory not sure what to do when we find multiple plugins would need additional criteria

# File lib/retrospec/plugins.rb, line 38
def discover_plugin(module_path)
   plugin = plugin_classes.find {|c| c.send(:valid_module_dir?, module_path) }
   raise NoSuitablePluginFoundException unless plugin
   plugin
end
discover_plugin_by_name(name) click to toggle source
# File lib/retrospec/plugins.rb, line 44
def discover_plugin_by_name(name)
  plugin = plugin_classes.find {|c| c.send(:plugin_name, name) }
  raise NoSuitablePluginFoundException unless plugin
  plugin
end
excluded_classes() click to toggle source
# File lib/retrospec/plugins.rb, line 13
def excluded_classes
  [Retrospec::Plugins::V1::ContextObject,Retrospec::Plugins::V1::Plugin]
end
gem_dir() click to toggle source
# File lib/retrospec/plugins.rb, line 50
def gem_dir
  File.expand_path("../../../", __FILE__)
end
get_remote_data(url) click to toggle source
# File lib/retrospec/plugins.rb, line 63
def get_remote_data(url)
  require "net/https"
  require "uri"
  uri = URI.parse(url)
  if uri.kind_of?(URI::HTTP) or uri.kind_of?(URI::HTTPS)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    #http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
    YAML.load(response.body)
  else
    {}
  end
end
installed_plugins() click to toggle source
# File lib/retrospec/plugins.rb, line 31
def installed_plugins
  Retrospec::PluginLoader.retrospec_gem_list
end
load_plugins() click to toggle source

loads the plugins (all of them)

# File lib/retrospec/plugins.rb, line 9
def load_plugins
  Retrospec::PluginLoader.load_from_gems('v1')
end
plugin_classes() click to toggle source

returns an array of plugin classes by looking in the object space for all loaded classes that start with Retrospec::Plugins::V1

# File lib/retrospec/plugins.rb, line 19
def plugin_classes
  unless @plugin_classes
    load_plugins
    @plugin_classes = ObjectSpace.each_object(Class).find_all { |c| c.name =~ /Retrospec::Plugins/} - excluded_classes || []
  end
  @plugin_classes
end
plugin_map() click to toggle source
# File lib/retrospec/plugins.rb, line 27
def plugin_map
  @plugin_map ||= Hash[plugin_classes.map { |gem| [gem.send(:plugin_name) , gem] }]
end