Module: Retrospec::Plugins

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

Defined Under Namespace

Modules: V1

Instance Method Summary collapse

Instance Method Details

#available_pluginsObject



54
55
56
57
58
59
60
61
# 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) ⇒ 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



38
39
40
41
42
# 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) ⇒ Object



44
45
46
47
48
# 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_classesObject



13
14
15
# File 'lib/retrospec/plugins.rb', line 13

def excluded_classes
  [Retrospec::Plugins::V1::ContextObject,Retrospec::Plugins::V1::Plugin]
end

#gem_dirObject



50
51
52
# File 'lib/retrospec/plugins.rb', line 50

def gem_dir
  File.expand_path("../../../", __FILE__)
end

#get_remote_data(url) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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_pluginsObject



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

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



19
20
21
22
23
24
25
# 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_mapObject



27
28
29
# File 'lib/retrospec/plugins.rb', line 27

def plugin_map
  @plugin_map ||= Hash[plugin_classes.map { |gem| [gem.send(:plugin_name) , gem] }]
end