Class: Derelict::Parser::PluginList

Inherits:
Derelict::Parser show all
Extended by:
Memoist
Defined in:
lib/derelict/parser/plugin_list.rb,
lib/derelict/parser/plugin_list/invalid_format.rb,
lib/derelict/parser/plugin_list/needs_reinstall.rb

Overview

Parses the output of “vagrant plugin list”

Defined Under Namespace

Classes: InvalidFormat, NeedsReinstall

Constant Summary collapse

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)
%r[
  ^(.*)                  # Plugin name starts at the start of the line.
  \                      # Version is separated by a space character,
  \(([0-9\-_.]+)(, .*)?\) # contains version string surrounded by brackets
  $                      # at the end of the line.
]x
NEEDS_REINSTALL =

Regexp to determine whether plugins need to be reinstalled

%r[
  ^The\splugins\sbelow\swill\snot\sbe\sloaded\suntil\sthey're\s
  uninstalled\sand\sreinstalled:$
]x

Instance Attribute Summary

Attributes inherited from Derelict::Parser

#output

Instance Method Summary collapse

Methods inherited from Derelict::Parser

#initialize

Methods included from Utils::Logger

#logger

Constructor Details

This class inherits a constructor from Derelict::Parser

Instance Method Details

#descriptionObject

Provides a description of this Parser

Mainly used for log messages.



43
44
45
# File 'lib/derelict/parser/plugin_list.rb', line 43

def description
  "Derelict::Parser::PluginList instance"
end

#needs_reinstall?Boolean

Determines if old plugins need to be reinstalled

Returns:

  • (Boolean)


36
37
38
# File 'lib/derelict/parser/plugin_list.rb', line 36

def needs_reinstall?
  output =~ NEEDS_REINSTALL
end

#pluginsObject

Retrieves a Set containing all the plugins from the output

Raises:



30
31
32
33
# File 'lib/derelict/parser/plugin_list.rb', line 30

def plugins
  raise NeedsReinstall, output if needs_reinstall?
  plugin_lines.map {|l| parse_line l.match(PARSE_PLUGIN) }.to_set
end