lib/vagrant-notify/config.rb in vagrant-notify-0.5.1 vs lib/vagrant-notify/config.rb in vagrant-notify-0.5.2

- old
+ new

@@ -1,12 +1,13 @@ module Vagrant module Notify class Config < Vagrant.plugin(2, :config) - attr_accessor :enable + attr_accessor :enable, :bind_ip def initialize() - @enable = UNSET_VALUE + @enable = UNSET_VALUE + @bind_ip = UNSET_VALUE end def validate(machine) errors = _detected_errors @@ -17,23 +18,44 @@ end if @enable != 0 if @enable != false && @enable != true errors << "Unknown option: #{@enable}" + end + end - { "notify" => errors } + if backed_by_supported_provider?(machine) + if @bind_ip.is_a?(String) + require "resolv" + unless @bind_ip =~ Resolv::IPv4::Regex + errors << "Invalid bind IP address: #{@bind_ip}" + end + elsif @bind_ip.is_a?(FalseClass) || @bind_ip.is_a?(Fixnum) || @bind_ip.is_a?(Array) || @bind_ip.is_a?(Hash) + errors << "Unknown bind IP address: #{@bind_ip}" + else + @bind_ip = SUPPORTED_PROVIDERS[machine.provider_name] end + else + machine.ui.warn("#{machine.provider_name.to_s} provider is not supported by vagrant-notify. Please feel free to open a new issue https://github.com/fgrehm/vagrant-notify/issues") + + @enable = false end + + { "notify" => errors } end def finalize! @enable = 0 if @enable == UNSET_VALUE + @bind_ip = @bind_ip if @bind_ip == UNSET_VALUE end private def backed_by_cloud_provider?(machine) CLOUD_PROVIDERS.include?(machine.provider_name.to_s) + end + def backed_by_supported_provider?(machine) + SUPPORTED_PROVIDERS.has_key?(machine.provider_name) end end end end