Class: VagrantPlugins::DevCommands::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/devcommands/registry.rb,
lib/vagrant/devcommands/registry/messager.rb,
lib/vagrant/devcommands/registry/resolver.rb,
lib/vagrant/devcommands/registry/validator.rb

Overview

Registry for definitions from the Commandfile

Defined Under Namespace

Classes: Messager, Resolver, Validator

Constant Summary collapse

RESERVED_COMMANDS =
%w[completion-data help version].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Registry



11
12
13
14
15
16
17
18
# File 'lib/vagrant/devcommands/registry.rb', line 11

def initialize(env)
  @env      = env
  @messager = Registry::Messager.new(@env)

  @chains          = {}
  @commands        = {}
  @command_aliases = {}
end

Instance Attribute Details

#chainsObject

Returns the value of attribute chains.



7
8
9
# File 'lib/vagrant/devcommands/registry.rb', line 7

def chains
  @chains
end

#command_aliasesObject

Returns the value of attribute command_aliases.



9
10
11
# File 'lib/vagrant/devcommands/registry.rb', line 9

def command_aliases
  @command_aliases
end

#commandsObject

Returns the value of attribute commands.



8
9
10
# File 'lib/vagrant/devcommands/registry.rb', line 8

def commands
  @commands
end

Instance Method Details

#available?(name) ⇒ Boolean



20
21
22
# File 'lib/vagrant/devcommands/registry.rb', line 20

def available?(name)
  valid_chain?(name) || valid_command?(name) || valid_command_alias?(name)
end

#read_commandfile(commandfile) ⇒ Object



24
25
26
27
28
29
# File 'lib/vagrant/devcommands/registry.rb', line 24

def read_commandfile(commandfile)
  register(Commandfile::Reader.new(commandfile, @env).read)

  Registry::Resolver.new(@messager).resolve_naming_conflicts(self)
  Registry::Validator.new(@messager).validate_entries(self)
end

#reserved_command?(command) ⇒ Boolean



31
32
33
# File 'lib/vagrant/devcommands/registry.rb', line 31

def reserved_command?(command)
  RESERVED_COMMANDS.include?(command)
end

#valid_chain?(chain) ⇒ Boolean



35
36
37
# File 'lib/vagrant/devcommands/registry.rb', line 35

def valid_chain?(chain)
  @chains.include?(chain)
end

#valid_command?(command) ⇒ Boolean



39
40
41
# File 'lib/vagrant/devcommands/registry.rb', line 39

def valid_command?(command)
  @commands.include?(command) || reserved_command?(command)
end

#valid_command_alias?(name) ⇒ Boolean



43
44
45
# File 'lib/vagrant/devcommands/registry.rb', line 43

def valid_command_alias?(name)
  @command_aliases.include?(name)
end