bind-zone-parser 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,9 @@
32
32
  action srv { record[:type] = :srv }
33
33
  action cname { record[:type] = :cname }
34
34
 
35
+ action store_opt_ttl { @ttl = record[:ttl] }
36
+ action store_opt_origin { @origin = record[:domain] }
37
+
35
38
  sp = space+;
36
39
  newline = "\n";
37
40
  comment = space* ";" [^\n]* newline;
@@ -83,11 +86,17 @@
83
86
  | soa_record
84
87
  | srv_record;
85
88
 
86
- main := (newline | comment | record)*;
89
+ opt_ttl = "$TTL" sp ttl %store_opt_ttl;
90
+ opt_origin = "$ORIGIN" sp fqdname %store_opt_origin;
91
+ option = (opt_ttl | opt_origin) endofline;
92
+
93
+ main := (newline | comment | option | record)*;
87
94
  }%%
88
95
 
89
96
  module Bind
90
97
  class ZoneParser
98
+ attr_reader :ttl, :origin
99
+
91
100
  def self.parse(zone)
92
101
  new.parse(zone)
93
102
  end
@@ -1,5 +1,6 @@
1
1
  ; Zone database file for example.com zone
2
2
 
3
+ $ORIGIN example.com.
3
4
  @ 86400 IN SOA ns1.example.com. hostmaster (
4
5
  2010080201 ; Serial number
5
6
  3600 ; Refresh
data/test/test_zone.rb CHANGED
@@ -1,13 +1,31 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestBindZone < Test::Unit::TestCase
4
- context ".load_file" do
4
+ context "Bind::Zone" do
5
5
  setup do
6
6
  @zone_file = File.expand_path('../examples/example.com.db', __FILE__)
7
- end
8
- should "return new zone with the records from the file" do
9
7
  @zone = Bind::Zone.load_file(@zone_file)
10
- assert !@zone.records.empty?
8
+ end
9
+ context ".load_file" do
10
+ should "return new zone with the records from the file" do
11
+ assert !@zone.records.empty?
12
+ end
13
+ end
14
+ context "#origin" do
15
+ should "get origin from zone $ORIGIN definition" do
16
+ assert_equal "example.com.", @zone.origin
17
+ end
18
+ end
19
+ context "#records" do
20
+ setup do
21
+ @records = @zone.records
22
+ end
23
+ should "not be empty" do
24
+ assert !@records.empty?
25
+ end
26
+ should "change any blank owners to named" do
27
+ assert @records.all? { |r| r[:owner] != "" }
28
+ end
11
29
  end
12
30
  end
13
31
  end
@@ -160,5 +160,25 @@ EOF
160
160
  assert @zone_parser.parse(multiline)
161
161
  end
162
162
  end
163
+ context "Options" do
164
+ context "$TTL option" do
165
+ should "parse the option" do
166
+ assert @zone_parser.parse("$TTL 144000\n")
167
+ end
168
+ should "store the result" do
169
+ @zone_parser.parse("$TTL 144000\n")
170
+ assert_equal 144000, @zone_parser.ttl
171
+ end
172
+ end
173
+ context "$ORIGIN option" do
174
+ should "parse the option" do
175
+ assert @zone_parser.parse("$ORIGIN example.com.\n")
176
+ end
177
+ should "store the result" do
178
+ @zone_parser.parse("$ORIGIN example.com.\n")
179
+ assert_equal "example.com.", @zone_parser.origin
180
+ end
181
+ end
182
+ end
163
183
  end
164
184
  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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoff Garside
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-25 00:00:00 +01:00
18
+ date: 2010-08-26 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency