Sha256: 1dd6007ea3967517fd7b62be5241360a8b3e14eb9a77823c765f5402bc77fbfa
Contents?: true
Size: 1.34 KB
Versions: 3
Compression:
Stored size: 1.34 KB
Contents
require 'vagrant' module VagrantPlugins module Adam # Config definition to validate given configuration values class Config < Vagrant.plugin('2', :config) attr_accessor :provision_url def initialize @provision_url = UNSET_VALUE @logger = Log4r::Logger.new('vagrantplugins::adam::config') end def finalize! @provision_url = nil if @provision_url == UNSET_VALUE end def validate!(_machine) finalize! errors = [] unless @provision_url.nil? unless (valid_uri? @provision_url) || (valid_file? @provision_url) msg = <<-EOH '#{ @provision_url }' is not a valid filepath or URL EOH errors << msg end end if errors.any? rendered_errors = Vagrant::Util::TemplateRenderer.render( 'config/validation_failed', errors: { 'vagrant-adam' => errors } ) fail Vagrant::Errors::ConfigInvalid, errors: rendered_errors end end private def valid_uri?(value) uri = URI.parse value uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) rescue URI::InvalidURIError false end def valid_file?(value) File.file?(value) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
vagrant-adam-0.3.0a | lib/vagrant-adam/config.rb |
vagrant-adam-0.2.0a | lib/vagrant-adam/config.rb |
vagrant-adam-0.1.0a | lib/vagrant-adam/config.rb |