Class: VagrantDockerHostsManager::Config
- Inherits:
-
Object
- Object
- VagrantDockerHostsManager::Config
- Defined in:
- lib/vagrant-docker-hosts-manager/config.rb
Overview
Vagrant configuration for managed host entries.
Instance Attribute Summary collapse
-
#container_name ⇒ String?
Docker container used for automatic IP discovery.
-
#domain ⇒ String?
Single domain to resolve from
iporcontainer_name. -
#domains ⇒ Hash{String=>String}
Mapping of domain names to IP addresses.
-
#ip ⇒ String?
Static IPv4 address for
domain. -
#locale ⇒ String?
Optional locale code.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #validate(_machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 24 def initialize @domains = UNSET_VALUE @domain = UNSET_VALUE @container_name = UNSET_VALUE @ip = UNSET_VALUE @locale = UNSET_VALUE @verbose = UNSET_VALUE end |
Instance Attribute Details
#container_name ⇒ String?
Returns Docker container used for automatic IP discovery.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 16 class Config < Vagrant.plugin("2", :config) attr_accessor :domains attr_accessor :domain attr_accessor :container_name attr_accessor :ip attr_accessor :locale attr_accessor :verbose def initialize @domains = UNSET_VALUE @domain = UNSET_VALUE @container_name = UNSET_VALUE @ip = UNSET_VALUE @locale = UNSET_VALUE @verbose = UNSET_VALUE end def finalize! @domains = {} if @domains == UNSET_VALUE @domain = nil if @domain == UNSET_VALUE @container_name = nil if @container_name == UNSET_VALUE @ip = nil if @ip == UNSET_VALUE @locale = nil if @locale == UNSET_VALUE @verbose = false if @verbose == UNSET_VALUE end def validate(_machine) errors = [] return { "vagrant-docker-hosts-manager" => errors } unless configured? if (@domains.nil? || @domains.empty?) && (@domain.nil? || @domain.strip.empty?) errors << "You must configure at least one domain: " \ "`config.docker_hosts.domain = \"example.test\"` or set " \ "`config.docker_hosts.domains = {\"example.test\" => \"172.28.0.10\"}`" end unless @domains.is_a?(Hash) errors << "`domains` must be a Hash of { \\\"domain\\\" => \\\"ip\\\" }" end if @ip && !@ip.to_s.match?(/\A\d{1,3}(\.\d{1,3}){3}\z/) errors << "`ip` must be IPv4 like 172.28.0.10" end if @locale && !%w[en fr].include?(@locale.to_s[0, 2].downcase) errors << "`locale` must be 'en' or 'fr'." end { "vagrant-docker-hosts-manager" => errors } end private def configured? (@domains.is_a?(Hash) && !@domains.empty?) || present?(@domain) || present?(@container_name) || present?(@ip) end def present?(value) !value.nil? && !value.to_s.strip.empty? end end |
#domain ⇒ String?
Returns Single domain to resolve from ip or container_name.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 16 class Config < Vagrant.plugin("2", :config) attr_accessor :domains attr_accessor :domain attr_accessor :container_name attr_accessor :ip attr_accessor :locale attr_accessor :verbose def initialize @domains = UNSET_VALUE @domain = UNSET_VALUE @container_name = UNSET_VALUE @ip = UNSET_VALUE @locale = UNSET_VALUE @verbose = UNSET_VALUE end def finalize! @domains = {} if @domains == UNSET_VALUE @domain = nil if @domain == UNSET_VALUE @container_name = nil if @container_name == UNSET_VALUE @ip = nil if @ip == UNSET_VALUE @locale = nil if @locale == UNSET_VALUE @verbose = false if @verbose == UNSET_VALUE end def validate(_machine) errors = [] return { "vagrant-docker-hosts-manager" => errors } unless configured? if (@domains.nil? || @domains.empty?) && (@domain.nil? || @domain.strip.empty?) errors << "You must configure at least one domain: " \ "`config.docker_hosts.domain = \"example.test\"` or set " \ "`config.docker_hosts.domains = {\"example.test\" => \"172.28.0.10\"}`" end unless @domains.is_a?(Hash) errors << "`domains` must be a Hash of { \\\"domain\\\" => \\\"ip\\\" }" end if @ip && !@ip.to_s.match?(/\A\d{1,3}(\.\d{1,3}){3}\z/) errors << "`ip` must be IPv4 like 172.28.0.10" end if @locale && !%w[en fr].include?(@locale.to_s[0, 2].downcase) errors << "`locale` must be 'en' or 'fr'." end { "vagrant-docker-hosts-manager" => errors } end private def configured? (@domains.is_a?(Hash) && !@domains.empty?) || present?(@domain) || present?(@container_name) || present?(@ip) end def present?(value) !value.nil? && !value.to_s.strip.empty? end end |
#domains ⇒ Hash{String=>String}
Returns Mapping of domain names to IP addresses.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 16 class Config < Vagrant.plugin("2", :config) attr_accessor :domains attr_accessor :domain attr_accessor :container_name attr_accessor :ip attr_accessor :locale attr_accessor :verbose def initialize @domains = UNSET_VALUE @domain = UNSET_VALUE @container_name = UNSET_VALUE @ip = UNSET_VALUE @locale = UNSET_VALUE @verbose = UNSET_VALUE end def finalize! @domains = {} if @domains == UNSET_VALUE @domain = nil if @domain == UNSET_VALUE @container_name = nil if @container_name == UNSET_VALUE @ip = nil if @ip == UNSET_VALUE @locale = nil if @locale == UNSET_VALUE @verbose = false if @verbose == UNSET_VALUE end def validate(_machine) errors = [] return { "vagrant-docker-hosts-manager" => errors } unless configured? if (@domains.nil? || @domains.empty?) && (@domain.nil? || @domain.strip.empty?) errors << "You must configure at least one domain: " \ "`config.docker_hosts.domain = \"example.test\"` or set " \ "`config.docker_hosts.domains = {\"example.test\" => \"172.28.0.10\"}`" end unless @domains.is_a?(Hash) errors << "`domains` must be a Hash of { \\\"domain\\\" => \\\"ip\\\" }" end if @ip && !@ip.to_s.match?(/\A\d{1,3}(\.\d{1,3}){3}\z/) errors << "`ip` must be IPv4 like 172.28.0.10" end if @locale && !%w[en fr].include?(@locale.to_s[0, 2].downcase) errors << "`locale` must be 'en' or 'fr'." end { "vagrant-docker-hosts-manager" => errors } end private def configured? (@domains.is_a?(Hash) && !@domains.empty?) || present?(@domain) || present?(@container_name) || present?(@ip) end def present?(value) !value.nil? && !value.to_s.strip.empty? end end |
#ip ⇒ String?
Returns Static IPv4 address for domain.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 16 class Config < Vagrant.plugin("2", :config) attr_accessor :domains attr_accessor :domain attr_accessor :container_name attr_accessor :ip attr_accessor :locale attr_accessor :verbose def initialize @domains = UNSET_VALUE @domain = UNSET_VALUE @container_name = UNSET_VALUE @ip = UNSET_VALUE @locale = UNSET_VALUE @verbose = UNSET_VALUE end def finalize! @domains = {} if @domains == UNSET_VALUE @domain = nil if @domain == UNSET_VALUE @container_name = nil if @container_name == UNSET_VALUE @ip = nil if @ip == UNSET_VALUE @locale = nil if @locale == UNSET_VALUE @verbose = false if @verbose == UNSET_VALUE end def validate(_machine) errors = [] return { "vagrant-docker-hosts-manager" => errors } unless configured? if (@domains.nil? || @domains.empty?) && (@domain.nil? || @domain.strip.empty?) errors << "You must configure at least one domain: " \ "`config.docker_hosts.domain = \"example.test\"` or set " \ "`config.docker_hosts.domains = {\"example.test\" => \"172.28.0.10\"}`" end unless @domains.is_a?(Hash) errors << "`domains` must be a Hash of { \\\"domain\\\" => \\\"ip\\\" }" end if @ip && !@ip.to_s.match?(/\A\d{1,3}(\.\d{1,3}){3}\z/) errors << "`ip` must be IPv4 like 172.28.0.10" end if @locale && !%w[en fr].include?(@locale.to_s[0, 2].downcase) errors << "`locale` must be 'en' or 'fr'." end { "vagrant-docker-hosts-manager" => errors } end private def configured? (@domains.is_a?(Hash) && !@domains.empty?) || present?(@domain) || present?(@container_name) || present?(@ip) end def present?(value) !value.nil? && !value.to_s.strip.empty? end end |
#locale ⇒ String?
Returns Optional locale code.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 16 class Config < Vagrant.plugin("2", :config) attr_accessor :domains attr_accessor :domain attr_accessor :container_name attr_accessor :ip attr_accessor :locale attr_accessor :verbose def initialize @domains = UNSET_VALUE @domain = UNSET_VALUE @container_name = UNSET_VALUE @ip = UNSET_VALUE @locale = UNSET_VALUE @verbose = UNSET_VALUE end def finalize! @domains = {} if @domains == UNSET_VALUE @domain = nil if @domain == UNSET_VALUE @container_name = nil if @container_name == UNSET_VALUE @ip = nil if @ip == UNSET_VALUE @locale = nil if @locale == UNSET_VALUE @verbose = false if @verbose == UNSET_VALUE end def validate(_machine) errors = [] return { "vagrant-docker-hosts-manager" => errors } unless configured? if (@domains.nil? || @domains.empty?) && (@domain.nil? || @domain.strip.empty?) errors << "You must configure at least one domain: " \ "`config.docker_hosts.domain = \"example.test\"` or set " \ "`config.docker_hosts.domains = {\"example.test\" => \"172.28.0.10\"}`" end unless @domains.is_a?(Hash) errors << "`domains` must be a Hash of { \\\"domain\\\" => \\\"ip\\\" }" end if @ip && !@ip.to_s.match?(/\A\d{1,3}(\.\d{1,3}){3}\z/) errors << "`ip` must be IPv4 like 172.28.0.10" end if @locale && !%w[en fr].include?(@locale.to_s[0, 2].downcase) errors << "`locale` must be 'en' or 'fr'." end { "vagrant-docker-hosts-manager" => errors } end private def configured? (@domains.is_a?(Hash) && !@domains.empty?) || present?(@domain) || present?(@container_name) || present?(@ip) end def present?(value) !value.nil? && !value.to_s.strip.empty? end end |
#verbose ⇒ Object
Returns the value of attribute verbose.
22 23 24 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 22 def verbose @verbose end |
Instance Method Details
#finalize! ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 33 def finalize! @domains = {} if @domains == UNSET_VALUE @domain = nil if @domain == UNSET_VALUE @container_name = nil if @container_name == UNSET_VALUE @ip = nil if @ip == UNSET_VALUE @locale = nil if @locale == UNSET_VALUE @verbose = false if @verbose == UNSET_VALUE end |
#validate(_machine) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vagrant-docker-hosts-manager/config.rb', line 42 def validate(_machine) errors = [] return { "vagrant-docker-hosts-manager" => errors } unless configured? if (@domains.nil? || @domains.empty?) && (@domain.nil? || @domain.strip.empty?) errors << "You must configure at least one domain: " \ "`config.docker_hosts.domain = \"example.test\"` or set " \ "`config.docker_hosts.domains = {\"example.test\" => \"172.28.0.10\"}`" end unless @domains.is_a?(Hash) errors << "`domains` must be a Hash of { \\\"domain\\\" => \\\"ip\\\" }" end if @ip && !@ip.to_s.match?(/\A\d{1,3}(\.\d{1,3}){3}\z/) errors << "`ip` must be IPv4 like 172.28.0.10" end if @locale && !%w[en fr].include?(@locale.to_s[0, 2].downcase) errors << "`locale` must be 'en' or 'fr'." end { "vagrant-docker-hosts-manager" => errors } end |