bind-zone-parser 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bind-zone-parser}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Geoff Garside"]
data/lib/bind/zone.rb CHANGED
@@ -12,6 +12,16 @@ module Bind
12
12
  @origin = @parser.origin
13
13
  update_blank_owners
14
14
  end
15
+ def origin=(v)
16
+ @origin = v
17
+ @origin << '.' unless @origin[-1,1] == '.'
18
+ end
19
+ def qualified_records
20
+ raise "Please set origin before calling this function" if @origin.nil?
21
+ @records.map do |record|
22
+ qualify_record(record.dup)
23
+ end
24
+ end
15
25
  protected
16
26
  def update_blank_owners
17
27
  last_owner = nil
@@ -20,5 +30,18 @@ module Bind
20
30
  last_owner = record[:owner]
21
31
  end
22
32
  end
33
+ def qualify_record(record)
34
+ [:owner, :target, :mbox, :domain].each do |key|
35
+ if record.has_key?(key)
36
+ record[key] = qualify_name(record[key])
37
+ end
38
+ end
39
+ record
40
+ end
41
+ def qualify_name(dname)
42
+ return if dname.nil?
43
+ return @origin if dname == '@'
44
+ "#{dname}.#{@origin}" if dname[-1,1] != '.'
45
+ end
23
46
  end
24
47
  end
data/test/test_zone.rb CHANGED
@@ -16,6 +16,16 @@ class TestBindZone < Test::Unit::TestCase
16
16
  assert_equal "example.com.", @zone.origin
17
17
  end
18
18
  end
19
+ context "#origin=" do
20
+ should "append . if unqualified" do
21
+ @zone.origin = "example.com"
22
+ assert_equal "example.com.", @zone.origin
23
+ end
24
+ should "not append . if qualified" do
25
+ @zone.origin = "example.com."
26
+ assert_equal "example.com.", @zone.origin
27
+ end
28
+ end
19
29
  context "#records" do
20
30
  setup do
21
31
  @records = @zone.records
@@ -27,5 +37,26 @@ class TestBindZone < Test::Unit::TestCase
27
37
  assert @records.all? { |r| r[:owner] != "" }
28
38
  end
29
39
  end
40
+ context "#qualified_records" do
41
+ setup do
42
+ @records = @zone.qualified_records
43
+ @olen = @zone.origin.length
44
+ end
45
+ should "expand all @ origins" do
46
+ assert @records.all? { |r| r[:owner] != "@" }
47
+ end
48
+ should "qualify all owner fields" do
49
+ assert @records.all? { |r| if r[:owner] then r[:owner][-@olen, @olen] == @zone.origin else true end }
50
+ end
51
+ should "qualify all target fields" do
52
+ assert @records.all? { |r| if r[:target] then r[:target][-@olen, @olen] == @zone.origin else true end }
53
+ end
54
+ should "qualify all mbox fields" do
55
+ assert @records.all? { |r| if r[:mbox] then r[:mbox][-@olen, @olen] == @zone.origin else true end }
56
+ end
57
+ should "qualify all domain fields" do
58
+ assert @records.all? { |r| if r[:domain] then r[:domain][-@olen, @olen] == @zone.origin else true end }
59
+ end
60
+ end
30
61
  end
31
62
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bind-zone-parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoff Garside