Class: VagrantPlugins::Exec::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::Exec::Config
- Defined in:
- lib/vagrant-exec/config.rb
Constant Summary collapse
- DEFAULT_SETTINGS =
{ cmd: '*', opts: { directory: '/vagrant' } }.freeze
Instance Method Summary collapse
-
#commands(*args) ⇒ Object
Retrieve or add command.
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #validate(_) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
12 13 14 |
# File 'lib/vagrant-exec/config.rb', line 12 def initialize @commands = UNSET_VALUE end |
Instance Method Details
#commands ⇒ Object #commands(command, options) ⇒ Object
Retrieve or add command.
30 31 32 33 34 35 36 37 38 |
# File 'lib/vagrant-exec/config.rb', line 30 def commands(*args) @commands = [] if @commands == UNSET_VALUE if args.empty? @commands else @commands << { cmd: args[0], opts: args[1] || {} } end end |
#finalize! ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vagrant-exec/config.rb', line 67 def finalize! if @commands == UNSET_VALUE @commands = [DEFAULT_SETTINGS.dup] else # add default settings and merge options for splat splats, commands = @commands.partition { |command| command[:cmd] == '*' } commands.unshift(DEFAULT_SETTINGS.dup) splats.each { |splat| commands.first[:opts].merge!(splat[:opts]) } @commands = commands end end |
#validate(_) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vagrant-exec/config.rb', line 40 def validate(_) finalize! errors = _detected_errors @commands.each do |command| cmd, opts = command[:cmd], command[:opts] if !cmd.is_a?(String) && !array_of_strings?(cmd) errors << "Commands should be String or Array<String>, received: #{cmd.inspect}" end if opts.has_key?(:directory) && !opts[:directory].is_a?(String) errors << ":directory should be String, received: #{opts[:directory].inspect}" end if opts.has_key?(:prepend) && !opts[:prepend].is_a?(String) errors << ":prepend should be String, received: #{opts[:prepend].inspect}" end if opts.has_key?(:env) && !opts[:env].is_a?(Hash) errors << ":env should be Hash, received: #{opts[:env].inspect}" end end { 'exec' => errors } end |