class Derelict::Parser::PluginList

Parses the output of “vagrant plugin list”

Constants

NEEDS_REINSTALL

Regexp to determine whether plugins need to be reinstalled

PARSE_PLUGIN

Regexp to parse a plugin line into a plugin name and version

Capture groups:

1. Plugin name, as listed in the output
2. Currently installed version (without surrounding brackets)

Public Instance Methods

description() click to toggle source

Provides a description of this Parser

Mainly used for log messages.

# File lib/derelict/parser/plugin_list.rb, line 46
def description
  "Derelict::Parser::PluginList instance"
end
needs_reinstall?() click to toggle source

Determines if old plugins need to be reinstalled

# File lib/derelict/parser/plugin_list.rb, line 39
def needs_reinstall?
  output =~ NEEDS_REINSTALL
end
plugins() click to toggle source

Retrieves a Set containing all the plugins from the output

# File lib/derelict/parser/plugin_list.rb, line 33
def plugins
  raise NeedsReinstall, output if needs_reinstall?
  plugin_lines.map {|l| parse_line l.match(PARSE_PLUGIN) }.to_set
end

Private Instance Methods

parse_line(match) click to toggle source

Parses a single line of the output into a Plugin object

# File lib/derelict/parser/plugin_list.rb, line 58
def parse_line(match)
  raise InvalidFormat.new "Couldn't parse plugin" if match.nil?
  Derelict::Plugin.new *match.captures[0..1]
end
plugin_lines() click to toggle source

Retrieves an array of the plugin lines in the output

# File lib/derelict/parser/plugin_list.rb, line 52
def plugin_lines
  return [] if output.match /no plugins installed/i
  output.lines.grep(/^\w/)
end