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 Attribute Summary collapse
-
#binstubs_path ⇒ Object
Returns the value of attribute binstubs_path.
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.
14 15 16 17 |
# File 'lib/vagrant-exec/config.rb', line 14 def initialize @binstubs_path = UNSET_VALUE @commands = UNSET_VALUE end |
Instance Attribute Details
#binstubs_path ⇒ Object
Returns the value of attribute binstubs_path.
12 13 14 |
# File 'lib/vagrant-exec/config.rb', line 12 def binstubs_path @binstubs_path end |
Instance Method Details
#commands ⇒ Object #commands(command, options) ⇒ Object
Retrieve or add command.
33 34 35 36 37 38 39 40 41 |
# File 'lib/vagrant-exec/config.rb', line 33 def commands(*args) @commands = [] if @commands == UNSET_VALUE if args.empty? @commands else @commands << {cmd: args[0], opts: args[1] || {}} end end |
#finalize! ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vagrant-exec/config.rb', line 70 def finalize! @binstubs_path = 'bin' if @binstubs_path == UNSET_VALUE 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/vagrant-exec/config.rb', line 43 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 |