Class: VagrantPlugins::DevCommands::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/devcommands/registry.rb

Overview

Vagrant command registry

Constant Summary collapse

I18N_KEY =
'vagrant_devcommands.registry'.freeze
RESERVED_COMMANDS =
%w[completion-data help version].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Registry

Returns a new instance of Registry.



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

def initialize(env)
  @chains   = {}
  @commands = {}
  @env      = env
end

Instance Attribute Details

#chainsObject

Returns the value of attribute chains.



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

def chains
  @chains
end

#commandsObject

Returns the value of attribute commands.



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

def commands
  @commands
end

Instance Method Details

#available?(name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/vagrant/devcommands/registry.rb', line 17

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

#read_commandfile(commandfile) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vagrant/devcommands/registry.rb', line 21

def read_commandfile(commandfile)
  global = commandfile.path_global
  local  = commandfile.path

  contents = ''
  contents += "\n" + global.read unless global.nil?
  contents += "\n" + local.read unless local.nil?

  instance_eval(contents)
  resolve_naming_conflicts
  validate_chains
end

#reserved_command?(command) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#valid_chain?(chain) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#valid_command?(command) ⇒ Boolean

Returns:

  • (Boolean)


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

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