Class: DnsmasqConf
- Defined in:
- lib/vagrant-dnsmasq/includes/Dnsmasq.class.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #delete(domain) ⇒ Object
- #includes?(domain) ⇒ Boolean
-
#initialize(filename) ⇒ DnsmasqConf
constructor
A new instance of DnsmasqConf.
- #insert(domain, ip) ⇒ Object
Constructor Details
#initialize(filename) ⇒ DnsmasqConf
Returns a new instance of DnsmasqConf.
5 6 7 8 9 |
# File 'lib/vagrant-dnsmasq/includes/Dnsmasq.class.rb', line 5 def initialize(filename) raise ArgumentError, 'wrong filename' if filename.blank? raise IOError unless File.exists? filename @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/vagrant-dnsmasq/includes/Dnsmasq.class.rb', line 3 def filename @filename end |
Instance Method Details
#delete(domain) ⇒ Object
31 32 33 34 35 |
# File 'lib/vagrant-dnsmasq/includes/Dnsmasq.class.rb', line 31 def delete(domain) raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain delete_line_from_file(@filename, Regexp.new("address=/\.#{domain.name}")) end |
#includes?(domain) ⇒ Boolean
22 23 24 25 26 27 28 29 |
# File 'lib/vagrant-dnsmasq/includes/Dnsmasq.class.rb', line 22 def includes?(domain) raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain File.open(@filename, "r").each_line do |l| return true if Regexp.new("address=/\.#{domain.name}").match(l.strip) end return false end |
#insert(domain, ip) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vagrant-dnsmasq/includes/Dnsmasq.class.rb', line 11 def insert(domain, ip) raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain raise ArgumentError, 'invalid ip instance' unless ip.is_a? Ip delete(domain) if includes?(domain) File.open(@filename, 'a') { |file| file.write "\naddress=/#{domain.dotted}/#{ip.v4}" } end |