Module: Retrospec::Plugins

Included in:
Cli, Module
Defined in:
lib/retrospec/plugins.rb,
lib/retrospec/plugins/v1/module_helpers.rb

Defined Under Namespace

Modules: V1

Instance Method Summary collapse

Instance Method Details

#available_pluginsObject



41
42
43
# File 'lib/retrospec/plugins.rb', line 41

def available_plugins
   get_remote_data('https://raw.githubusercontent.com/nwops/retrospec/master/available_plugins.yaml')
end

#discover_plugin(module_path) ⇒ Object

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



29
30
31
32
33
# File 'lib/retrospec/plugins.rb', line 29

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) ⇒ Object



35
36
37
38
39
# File 'lib/retrospec/plugins.rb', line 35

def discover_plugin_by_name(name)
  plugin = plugin_classes.find {|c| c.send(:plugin_name, name) }
  raise NoSuitablePluginFoundException unless plugin
  plugin
end

#get_remote_data(url) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/retrospec/plugins.rb', line 45

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_pluginsObject



22
23
24
# File 'lib/retrospec/plugins.rb', line 22

def installed_plugins
  Retrospec::PluginLoader.retrospec_gem_list
end

#load_pluginsObject

loads the plugins (all of them)



9
10
11
# File 'lib/retrospec/plugins.rb', line 9

def load_plugins
  Retrospec::PluginLoader.load_from_gems('v1')
end

#plugin_classesObject

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



15
16
17
18
19
20
# File 'lib/retrospec/plugins.rb', line 15

def plugin_classes
  unless @plugin_classes
    load_plugins
    @plugin_classes = ObjectSpace.each_object(Class).find_all {|c| c.name =~ /Retrospec::Plugins/}
  end
end