devdnsd 3.1.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/.rubocop.yml +82 -0
- data/.travis-gemfile +4 -10
- data/.travis.yml +11 -5
- data/CHANGELOG.md +11 -0
- data/Gemfile +9 -8
- data/README.md +4 -5
- data/Rakefile +22 -6
- data/bin/devdnsd +42 -36
- data/config/devdnsd_config.sample +11 -11
- data/devdnsd.gemspec +7 -6
- data/doc/DevDNSd.html +6 -6
- data/doc/DevDNSd/{ApplicationMethods/Aliases.html → Aliases.html} +96 -100
- data/doc/DevDNSd/Application.html +2170 -1084
- data/doc/DevDNSd/Configuration.html +63 -33
- data/doc/DevDNSd/Errors.html +3 -3
- data/doc/DevDNSd/Errors/InvalidRule.html +3 -3
- data/doc/DevDNSd/{ApplicationMethods/System.html → OSX.html} +116 -489
- data/doc/DevDNSd/Rule.html +448 -749
- data/doc/DevDNSd/{ApplicationMethods/Server.html → Server.html} +77 -73
- data/doc/DevDNSd/System.html +895 -0
- data/doc/DevDNSd/Version.html +6 -6
- data/doc/_index.html +28 -27
- data/doc/class_list.html +6 -2
- data/doc/file.README.html +8 -9
- data/doc/file_list.html +5 -1
- data/doc/frames.html +1 -1
- data/doc/index.html +8 -9
- data/doc/js/full_list.js +4 -1
- data/doc/method_list.html +106 -84
- data/doc/top-level-namespace.html +3 -3
- data/lib/devdnsd.rb +10 -8
- data/lib/devdnsd/aliases.rb +171 -0
- data/lib/devdnsd/application.rb +93 -704
- data/lib/devdnsd/configuration.rb +20 -11
- data/lib/devdnsd/errors.rb +1 -1
- data/lib/devdnsd/osx.rb +217 -0
- data/lib/devdnsd/rule.rb +65 -94
- data/lib/devdnsd/server.rb +118 -0
- data/lib/devdnsd/system.rb +102 -0
- data/lib/devdnsd/version.rb +3 -3
- data/locales/en.yml +17 -16
- data/locales/it.yml +17 -16
- data/spec/devdnsd/application_spec.rb +188 -184
- data/spec/devdnsd/configuration_spec.rb +2 -2
- data/spec/devdnsd/rule_spec.rb +33 -34
- data/spec/resolver_helper.rb +10 -27
- data/spec/spec_helper.rb +21 -7
- metadata +36 -21
- data/doc/DevDNSd/ApplicationMethods.html +0 -125
- data/doc/DevDNSd/ApplicationMethods/System/ClassMethods.html +0 -538
- data/spec/coverage_helper.rb +0 -20
data/doc/DevDNSd/Rule.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Class: DevDNSd::Rule
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.7.
|
9
|
+
— Documentation by YARD 0.8.7.6
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -90,15 +90,11 @@
|
|
90
90
|
|
91
91
|
|
92
92
|
|
93
|
-
<dt class="r2">Includes:</dt>
|
94
|
-
<dd class="r2">Lazier::I18n</dd>
|
95
|
-
|
96
|
-
|
97
93
|
|
98
94
|
|
99
95
|
|
100
|
-
<dt class="
|
101
|
-
<dd class="
|
96
|
+
<dt class="r2 last">Defined in:</dt>
|
97
|
+
<dd class="r2 last">lib/devdnsd/rule.rb</dd>
|
102
98
|
|
103
99
|
</dl>
|
104
100
|
<div class="clear"></div>
|
@@ -266,7 +262,7 @@
|
|
266
262
|
<li class="public ">
|
267
263
|
<span class="summary_signature">
|
268
264
|
|
269
|
-
<a href="#create-class_method" title="create (class method)">+ (Rule) <strong>create</strong>(match
|
265
|
+
<a href="#create-class_method" title="create (class method)">+ (Rule) <strong>create</strong>(match: /.+/, reply: "127.0.0.1", type: :A, options: {}, &block) </a>
|
270
266
|
|
271
267
|
|
272
268
|
|
@@ -344,10 +340,12 @@
|
|
344
340
|
<li class="public ">
|
345
341
|
<span class="summary_signature">
|
346
342
|
|
347
|
-
<a href="#
|
343
|
+
<a href="#block%3F-instance_method" title="#block? (instance method)">- (Boolean) <strong>block?</strong> </a>
|
348
344
|
|
349
345
|
|
350
346
|
|
347
|
+
(also: #has_block?)
|
348
|
+
|
351
349
|
</span>
|
352
350
|
|
353
351
|
|
@@ -367,7 +365,7 @@
|
|
367
365
|
<li class="public ">
|
368
366
|
<span class="summary_signature">
|
369
367
|
|
370
|
-
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Rule) <strong>initialize</strong>(match
|
368
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Rule) <strong>initialize</strong>(match: /.+/, reply: "127.0.0.1", type: :A, options: {}, &block) </a>
|
371
369
|
|
372
370
|
|
373
371
|
|
@@ -392,7 +390,7 @@
|
|
392
390
|
<li class="public ">
|
393
391
|
<span class="summary_signature">
|
394
392
|
|
395
|
-
<a href="#
|
393
|
+
<a href="#match_host-instance_method" title="#match_host (instance method)">- (MatchData|Boolean|Nil) <strong>match_host</strong>(hostname) </a>
|
396
394
|
|
397
395
|
|
398
396
|
|
@@ -406,7 +404,7 @@
|
|
406
404
|
|
407
405
|
|
408
406
|
|
409
|
-
<span class="summary_desc"><div class='inline'><p>
|
407
|
+
<span class="summary_desc"><div class='inline'><p>Matches a hostname to the rule.</p>
|
410
408
|
</div></span>
|
411
409
|
|
412
410
|
</li>
|
@@ -415,10 +413,12 @@
|
|
415
413
|
<li class="public ">
|
416
414
|
<span class="summary_signature">
|
417
415
|
|
418
|
-
<a href="#
|
416
|
+
<a href="#regexp%3F-instance_method" title="#regexp? (instance method)">- (Boolean) <strong>regexp?</strong> </a>
|
419
417
|
|
420
418
|
|
421
419
|
|
420
|
+
(also: #is_regexp?)
|
421
|
+
|
422
422
|
</span>
|
423
423
|
|
424
424
|
|
@@ -429,7 +429,7 @@
|
|
429
429
|
|
430
430
|
|
431
431
|
|
432
|
-
<span class="summary_desc"><div class='inline'><p>
|
432
|
+
<span class="summary_desc"><div class='inline'><p>Checks if the rule is a regexp.</p>
|
433
433
|
</div></span>
|
434
434
|
|
435
435
|
</li>
|
@@ -461,14 +461,13 @@
|
|
461
461
|
</ul>
|
462
462
|
|
463
463
|
|
464
|
-
|
465
|
-
<div id="constructor_details" class="method_details_list">
|
464
|
+
<div id="constructor_details" class="method_details_list">
|
466
465
|
<h2>Constructor Details</h2>
|
467
466
|
|
468
467
|
<div class="method_details first">
|
469
468
|
<h3 class="signature first" id="initialize-instance_method">
|
470
469
|
|
471
|
-
- (<tt><span class='object_link'><a href="" title="DevDNSd::Rule (class)">Rule</a></span></tt>) <strong>initialize</strong>(match
|
470
|
+
- (<tt><span class='object_link'><a href="" title="DevDNSd::Rule (class)">Rule</a></span></tt>) <strong>initialize</strong>(match: /.+/, reply: "127.0.0.1", type: :A, options: {}, &block)
|
472
471
|
|
473
472
|
|
474
473
|
|
@@ -493,8 +492,6 @@
|
|
493
492
|
<span class='type'>(<tt>String|Regexp</tt>)</span>
|
494
493
|
|
495
494
|
|
496
|
-
<em class="default">(defaults to: <tt>/.+/</tt>)</em>
|
497
|
-
|
498
495
|
|
499
496
|
—
|
500
497
|
<div class='inline'><p>The pattern to match.</p>
|
@@ -507,14 +504,12 @@
|
|
507
504
|
<span class='name'>reply</span>
|
508
505
|
|
509
506
|
|
510
|
-
<span class='type'>(<tt>String</tt>)</span>
|
511
|
-
|
507
|
+
<span class='type'>(<tt>String|Symbol</tt>)</span>
|
512
508
|
|
513
|
-
<em class="default">(defaults to: <tt>"127.0.0.1"</tt>)</em>
|
514
509
|
|
515
510
|
|
516
511
|
—
|
517
|
-
<div class='inline'><p>The IP or hostname to reply back to the client.</p>
|
512
|
+
<div class='inline'><p>The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.</p>
|
518
513
|
</div>
|
519
514
|
|
520
515
|
</li>
|
@@ -527,8 +522,6 @@
|
|
527
522
|
<span class='type'>(<tt>Symbol</tt>)</span>
|
528
523
|
|
529
524
|
|
530
|
-
<em class="default">(defaults to: <tt>:A</tt>)</em>
|
531
|
-
|
532
525
|
|
533
526
|
—
|
534
527
|
<div class='inline'><p>The type of request to match.</p>
|
@@ -544,8 +537,6 @@
|
|
544
537
|
<span class='type'>(<tt>Hash</tt>)</span>
|
545
538
|
|
546
539
|
|
547
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
548
|
-
|
549
540
|
|
550
541
|
—
|
551
542
|
<div class='inline'><p>A list of options for the request.</p>
|
@@ -584,19 +575,15 @@
|
|
584
575
|
<pre class="lines">
|
585
576
|
|
586
577
|
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
41
|
592
|
-
42</pre>
|
578
|
+
74
|
579
|
+
75
|
580
|
+
76
|
581
|
+
77</pre>
|
593
582
|
</td>
|
594
583
|
<td>
|
595
|
-
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line
|
584
|
+
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 74</span>
|
596
585
|
|
597
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='
|
598
|
-
<span class='id identifier rubyid_i18n_setup'>i18n_setup</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
599
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span>
|
586
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
600
587
|
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
601
588
|
<span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
602
589
|
<span class='kw'>end</span></pre>
|
@@ -770,36 +757,7 @@
|
|
770
757
|
133
|
771
758
|
134
|
772
759
|
135
|
773
|
-
136
|
774
|
-
137
|
775
|
-
138
|
776
|
-
139
|
777
|
-
140
|
778
|
-
141
|
779
|
-
142
|
780
|
-
143
|
781
|
-
144
|
782
|
-
145
|
783
|
-
146
|
784
|
-
147
|
785
|
-
148
|
786
|
-
149
|
787
|
-
150
|
788
|
-
151
|
789
|
-
152
|
790
|
-
153
|
791
|
-
154
|
792
|
-
155
|
793
|
-
156
|
794
|
-
157
|
795
|
-
158
|
796
|
-
159
|
797
|
-
160
|
798
|
-
161
|
799
|
-
162
|
800
|
-
163
|
801
|
-
164
|
802
|
-
165</pre>
|
760
|
+
136</pre>
|
803
761
|
</td>
|
804
762
|
<td>
|
805
763
|
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 20</span>
|
@@ -811,19 +769,54 @@
|
|
811
769
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:options</span>
|
812
770
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:block</span>
|
813
771
|
|
814
|
-
<span class='
|
772
|
+
<span class='comment'># Class methods
|
773
|
+
</span> <span class='kw'>class</span> <span class='op'><<</span> <span class='kw'>self</span>
|
774
|
+
<span class='comment'># Creates a new rule.
|
775
|
+
</span> <span class='comment'>#
|
776
|
+
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
777
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
778
|
+
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
779
|
+
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
780
|
+
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
781
|
+
</span> <span class='comment'># @return [Rule] The new rule.
|
782
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
783
|
+
<span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
784
|
+
<span class='kw'>end</span>
|
785
|
+
|
786
|
+
<span class='comment'># Converts a class to the correspondent symbol.
|
787
|
+
</span> <span class='comment'>#
|
788
|
+
</span> <span class='comment'># @param klass [Class] The class to convert.
|
789
|
+
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
790
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
791
|
+
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
792
|
+
<span class='kw'>end</span>
|
793
|
+
|
794
|
+
<span class='comment'># Converts a symbol to the correspondent DNS resource class.
|
795
|
+
</span> <span class='comment'>#
|
796
|
+
</span> <span class='comment'># @param symbol [Symbol] The symbol to convert.
|
797
|
+
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
798
|
+
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
799
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
800
|
+
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
801
|
+
|
802
|
+
<span class='kw'>begin</span>
|
803
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
804
|
+
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
805
|
+
<span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
806
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_resource'>rule_invalid_resource</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
807
|
+
<span class='kw'>end</span>
|
808
|
+
<span class='kw'>end</span>
|
809
|
+
<span class='kw'>end</span>
|
815
810
|
|
816
811
|
<span class='comment'># Creates a new rule.
|
817
812
|
</span> <span class='comment'>#
|
818
813
|
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
819
|
-
</span> <span class='comment'># @param reply [String] The IP or hostname to reply back to the client.
|
814
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
820
815
|
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
821
816
|
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
822
817
|
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
823
818
|
</span> <span class='comment'># @see .create
|
824
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='
|
825
|
-
<span class='id identifier rubyid_i18n_setup'>i18n_setup</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
826
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span>
|
819
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
827
820
|
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
828
821
|
<span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
829
822
|
<span class='kw'>end</span>
|
@@ -832,123 +825,59 @@
|
|
832
825
|
</span> <span class='comment'>#
|
833
826
|
</span> <span class='comment'># @return [Array|Class] The class(es) for the current rule.
|
834
827
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class'>resource_class</span>
|
835
|
-
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='
|
828
|
+
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_cls'>cls</span><span class='op'>|</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_cls'>cls</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
836
829
|
<span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='op'>?</span> <span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span> <span class='op'>:</span> <span class='id identifier rubyid_classes'>classes</span>
|
837
830
|
<span class='kw'>end</span>
|
838
831
|
|
839
832
|
<span class='comment'># Checks if the rule is a regexp.
|
840
833
|
</span> <span class='comment'>#
|
841
834
|
</span> <span class='comment'># @return [Boolean] `true` if the rule is a Regexp, `false` otherwise.
|
842
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
835
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_regexp?'>regexp?</span>
|
843
836
|
<span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span>
|
844
837
|
<span class='kw'>end</span>
|
838
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:is_regexp?</span><span class='comma'>,</span> <span class='symbol'>:regexp?</span>
|
845
839
|
|
846
840
|
<span class='comment'># Checks if the rule is a regexp.
|
847
841
|
</span> <span class='comment'>#
|
848
842
|
</span> <span class='comment'># @return [Boolean] `true` if the rule has a block, `false` otherwise.
|
849
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
843
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_block?'>block?</span>
|
850
844
|
<span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
851
845
|
<span class='kw'>end</span>
|
846
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:has_block?</span><span class='comma'>,</span> <span class='symbol'>:block?</span>
|
852
847
|
|
853
848
|
<span class='comment'># Matches a hostname to the rule.
|
854
849
|
</span> <span class='comment'>#
|
855
850
|
</span> <span class='comment'># @param hostname [String] The hostname to match.
|
856
851
|
</span> <span class='comment'># @return [MatchData|Boolean|Nil] Return `true` or MatchData (if the pattern is a regexp) if the rule matches, `false` or `nil` otherwise.
|
857
852
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_match_host'>match_host</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
858
|
-
<span class='id identifier
|
859
|
-
<span class='kw'>end</span>
|
860
|
-
|
861
|
-
<span class='comment'># Creates a new rule.
|
862
|
-
</span> <span class='comment'>#
|
863
|
-
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
864
|
-
</span> <span class='comment'># @param reply_or_type [String|Symbol] The IP or hostname to reply back to the client (or the type of request to match, if a block is provided).
|
865
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match. This is ignored if a block is provided.
|
866
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
867
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
868
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
869
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
870
|
-
<span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='kw'>nil</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
871
|
-
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
853
|
+
<span class='id identifier rubyid_regexp?'>regexp?</span> <span class='op'>?</span> <span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='lparen'>(</span><span class='ivar'>@match</span> <span class='op'>==</span> <span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
872
854
|
<span class='kw'>end</span>
|
873
855
|
|
874
|
-
<span class='
|
875
|
-
</span> <span class='comment'>#
|
876
|
-
</span> <span class='comment'># @param klass [Class] The class to convert.
|
877
|
-
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
878
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
879
|
-
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
880
|
-
<span class='kw'>end</span>
|
856
|
+
<span class='id identifier rubyid_private'>private</span>
|
881
857
|
|
882
|
-
<span class='comment'>#
|
883
|
-
</span> <span class='
|
884
|
-
</span>
|
885
|
-
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
886
|
-
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
887
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
888
|
-
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
889
|
-
|
890
|
-
<span class='kw'>begin</span>
|
891
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
892
|
-
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
893
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_invalid_class'>invalid_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
894
|
-
<span class='kw'>end</span>
|
895
|
-
<span class='kw'>end</span>
|
858
|
+
<span class='comment'># :nodoc:
|
859
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
860
|
+
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
896
861
|
|
897
|
-
|
898
|
-
|
899
|
-
</span>
|
900
|
-
</span>
|
901
|
-
</span>
|
902
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
903
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
904
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
905
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
906
|
-
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
862
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='comment'># reply acts like a type, type is ignored
|
863
|
+
</span> <span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
864
|
+
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
865
|
+
<span class='kw'>else</span> <span class='comment'># reply acts like a reply
|
866
|
+
</span> <span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
907
867
|
<span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
908
|
-
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
|
909
|
-
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
910
|
-
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
911
868
|
<span class='kw'>end</span>
|
912
869
|
|
913
|
-
<span class='
|
914
|
-
</span>
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
<span class='comment'># Setups a new rule.
|
920
|
-
</span> <span class='comment'>#
|
921
|
-
</span> <span class='comment'># @param rv [Rule] The rule that is been created.
|
922
|
-
</span> <span class='comment'># @param reply_or_type [String|Symbol] The IP or hostname to reply back to the client (or the type of request to match, if a block is provided).
|
923
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match. This is ignored if a block is provided.
|
924
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
925
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
926
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
927
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
928
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
929
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_block'>block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
930
|
-
|
931
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='kw'>then</span> <span class='comment'># reply_or_type acts like a type, type is ignored
|
932
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
933
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
934
|
-
<span class='kw'>else</span> <span class='comment'># reply_or_type acts like a reply
|
935
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
936
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
937
|
-
<span class='kw'>end</span>
|
938
|
-
|
939
|
-
<span class='id identifier rubyid_rv'>rv</span>
|
940
|
-
<span class='kw'>end</span>
|
870
|
+
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
871
|
+
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
872
|
+
<span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='symbol'>:en</span>
|
873
|
+
<span class='ivar'>@i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
874
|
+
<span class='kw'>end</span>
|
941
875
|
|
942
|
-
|
943
|
-
</span>
|
944
|
-
</span>
|
945
|
-
</span>
|
946
|
-
|
947
|
-
</span> <span class='comment'># @param localizer [Localizer] A localizer object.
|
948
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='id identifier rubyid_localizer'>localizer</span><span class='rparen'>)</span>
|
949
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
950
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
951
|
-
<span class='kw'>end</span>
|
876
|
+
<span class='comment'># Validates a newly created rule.
|
877
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
878
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
879
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
880
|
+
<span class='kw'>end</span>
|
952
881
|
<span class='kw'>end</span></pre>
|
953
882
|
</td>
|
954
883
|
</tr>
|
@@ -1115,36 +1044,7 @@
|
|
1115
1044
|
133
|
1116
1045
|
134
|
1117
1046
|
135
|
1118
|
-
136
|
1119
|
-
137
|
1120
|
-
138
|
1121
|
-
139
|
1122
|
-
140
|
1123
|
-
141
|
1124
|
-
142
|
1125
|
-
143
|
1126
|
-
144
|
1127
|
-
145
|
1128
|
-
146
|
1129
|
-
147
|
1130
|
-
148
|
1131
|
-
149
|
1132
|
-
150
|
1133
|
-
151
|
1134
|
-
152
|
1135
|
-
153
|
1136
|
-
154
|
1137
|
-
155
|
1138
|
-
156
|
1139
|
-
157
|
1140
|
-
158
|
1141
|
-
159
|
1142
|
-
160
|
1143
|
-
161
|
1144
|
-
162
|
1145
|
-
163
|
1146
|
-
164
|
1147
|
-
165</pre>
|
1047
|
+
136</pre>
|
1148
1048
|
</td>
|
1149
1049
|
<td>
|
1150
1050
|
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 20</span>
|
@@ -1156,19 +1056,54 @@
|
|
1156
1056
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:options</span>
|
1157
1057
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:block</span>
|
1158
1058
|
|
1159
|
-
<span class='
|
1059
|
+
<span class='comment'># Class methods
|
1060
|
+
</span> <span class='kw'>class</span> <span class='op'><<</span> <span class='kw'>self</span>
|
1061
|
+
<span class='comment'># Creates a new rule.
|
1062
|
+
</span> <span class='comment'>#
|
1063
|
+
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1064
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
1065
|
+
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1066
|
+
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1067
|
+
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1068
|
+
</span> <span class='comment'># @return [Rule] The new rule.
|
1069
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1070
|
+
<span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1071
|
+
<span class='kw'>end</span>
|
1072
|
+
|
1073
|
+
<span class='comment'># Converts a class to the correspondent symbol.
|
1074
|
+
</span> <span class='comment'>#
|
1075
|
+
</span> <span class='comment'># @param klass [Class] The class to convert.
|
1076
|
+
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
1077
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1078
|
+
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
1079
|
+
<span class='kw'>end</span>
|
1080
|
+
|
1081
|
+
<span class='comment'># Converts a symbol to the correspondent DNS resource class.
|
1082
|
+
</span> <span class='comment'>#
|
1083
|
+
</span> <span class='comment'># @param symbol [Symbol] The symbol to convert.
|
1084
|
+
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
1085
|
+
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
1086
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1087
|
+
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
1088
|
+
|
1089
|
+
<span class='kw'>begin</span>
|
1090
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
1091
|
+
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
1092
|
+
<span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1093
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_resource'>rule_invalid_resource</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1094
|
+
<span class='kw'>end</span>
|
1095
|
+
<span class='kw'>end</span>
|
1096
|
+
<span class='kw'>end</span>
|
1160
1097
|
|
1161
1098
|
<span class='comment'># Creates a new rule.
|
1162
1099
|
</span> <span class='comment'>#
|
1163
1100
|
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1164
|
-
</span> <span class='comment'># @param reply [String] The IP or hostname to reply back to the client.
|
1101
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
1165
1102
|
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1166
1103
|
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1167
1104
|
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1168
1105
|
</span> <span class='comment'># @see .create
|
1169
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='
|
1170
|
-
<span class='id identifier rubyid_i18n_setup'>i18n_setup</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1171
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span>
|
1106
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1172
1107
|
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1173
1108
|
<span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1174
1109
|
<span class='kw'>end</span>
|
@@ -1177,123 +1112,59 @@
|
|
1177
1112
|
</span> <span class='comment'>#
|
1178
1113
|
</span> <span class='comment'># @return [Array|Class] The class(es) for the current rule.
|
1179
1114
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class'>resource_class</span>
|
1180
|
-
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='
|
1115
|
+
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_cls'>cls</span><span class='op'>|</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_cls'>cls</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1181
1116
|
<span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='op'>?</span> <span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span> <span class='op'>:</span> <span class='id identifier rubyid_classes'>classes</span>
|
1182
1117
|
<span class='kw'>end</span>
|
1183
1118
|
|
1184
1119
|
<span class='comment'># Checks if the rule is a regexp.
|
1185
1120
|
</span> <span class='comment'>#
|
1186
1121
|
</span> <span class='comment'># @return [Boolean] `true` if the rule is a Regexp, `false` otherwise.
|
1187
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
1122
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_regexp?'>regexp?</span>
|
1188
1123
|
<span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span>
|
1189
1124
|
<span class='kw'>end</span>
|
1125
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:is_regexp?</span><span class='comma'>,</span> <span class='symbol'>:regexp?</span>
|
1190
1126
|
|
1191
1127
|
<span class='comment'># Checks if the rule is a regexp.
|
1192
1128
|
</span> <span class='comment'>#
|
1193
1129
|
</span> <span class='comment'># @return [Boolean] `true` if the rule has a block, `false` otherwise.
|
1194
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
1130
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_block?'>block?</span>
|
1195
1131
|
<span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
1196
1132
|
<span class='kw'>end</span>
|
1133
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:has_block?</span><span class='comma'>,</span> <span class='symbol'>:block?</span>
|
1197
1134
|
|
1198
1135
|
<span class='comment'># Matches a hostname to the rule.
|
1199
1136
|
</span> <span class='comment'>#
|
1200
1137
|
</span> <span class='comment'># @param hostname [String] The hostname to match.
|
1201
1138
|
</span> <span class='comment'># @return [MatchData|Boolean|Nil] Return `true` or MatchData (if the pattern is a regexp) if the rule matches, `false` or `nil` otherwise.
|
1202
1139
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_match_host'>match_host</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
1203
|
-
<span class='id identifier
|
1140
|
+
<span class='id identifier rubyid_regexp?'>regexp?</span> <span class='op'>?</span> <span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='lparen'>(</span><span class='ivar'>@match</span> <span class='op'>==</span> <span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
1204
1141
|
<span class='kw'>end</span>
|
1205
1142
|
|
1206
|
-
<span class='
|
1207
|
-
</span> <span class='comment'>#
|
1208
|
-
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1209
|
-
</span> <span class='comment'># @param reply_or_type [String|Symbol] The IP or hostname to reply back to the client (or the type of request to match, if a block is provided).
|
1210
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match. This is ignored if a block is provided.
|
1211
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1212
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
1213
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
1214
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1215
|
-
<span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='kw'>nil</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1216
|
-
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1217
|
-
<span class='kw'>end</span>
|
1218
|
-
|
1219
|
-
<span class='comment'># Converts a class to the correspondent symbol.
|
1220
|
-
</span> <span class='comment'>#
|
1221
|
-
</span> <span class='comment'># @param klass [Class] The class to convert.
|
1222
|
-
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
1223
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1224
|
-
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
1225
|
-
<span class='kw'>end</span>
|
1143
|
+
<span class='id identifier rubyid_private'>private</span>
|
1226
1144
|
|
1227
|
-
<span class='comment'>#
|
1228
|
-
</span> <span class='
|
1229
|
-
</span>
|
1230
|
-
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
1231
|
-
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
1232
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1233
|
-
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
1234
|
-
|
1235
|
-
<span class='kw'>begin</span>
|
1236
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
1237
|
-
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
1238
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_invalid_class'>invalid_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1239
|
-
<span class='kw'>end</span>
|
1240
|
-
<span class='kw'>end</span>
|
1145
|
+
<span class='comment'># :nodoc:
|
1146
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1147
|
+
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
1241
1148
|
|
1242
|
-
|
1243
|
-
|
1244
|
-
</span>
|
1245
|
-
</span>
|
1246
|
-
</span>
|
1247
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1248
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1249
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1250
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1251
|
-
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
1149
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='comment'># reply acts like a type, type is ignored
|
1150
|
+
</span> <span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1151
|
+
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1152
|
+
<span class='kw'>else</span> <span class='comment'># reply acts like a reply
|
1153
|
+
</span> <span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
1252
1154
|
<span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1253
|
-
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
|
1254
|
-
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1255
|
-
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1256
|
-
<span class='kw'>end</span>
|
1257
|
-
|
1258
|
-
<span class='comment'># Validates a newly created rule.
|
1259
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1260
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1261
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1262
1155
|
<span class='kw'>end</span>
|
1263
1156
|
|
1264
|
-
<span class='
|
1265
|
-
</span>
|
1266
|
-
</span>
|
1267
|
-
</span>
|
1268
|
-
|
1269
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1270
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
1271
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
1272
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1273
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1274
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_block'>block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1275
|
-
|
1276
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='kw'>then</span> <span class='comment'># reply_or_type acts like a type, type is ignored
|
1277
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1278
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1279
|
-
<span class='kw'>else</span> <span class='comment'># reply_or_type acts like a reply
|
1280
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
1281
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1282
|
-
<span class='kw'>end</span>
|
1283
|
-
|
1284
|
-
<span class='id identifier rubyid_rv'>rv</span>
|
1285
|
-
<span class='kw'>end</span>
|
1157
|
+
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1158
|
+
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1159
|
+
<span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='symbol'>:en</span>
|
1160
|
+
<span class='ivar'>@i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1161
|
+
<span class='kw'>end</span>
|
1286
1162
|
|
1287
|
-
|
1288
|
-
</span>
|
1289
|
-
</span>
|
1290
|
-
</span>
|
1291
|
-
|
1292
|
-
</span> <span class='comment'># @param localizer [Localizer] A localizer object.
|
1293
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='id identifier rubyid_localizer'>localizer</span><span class='rparen'>)</span>
|
1294
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1295
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1296
|
-
<span class='kw'>end</span>
|
1163
|
+
<span class='comment'># Validates a newly created rule.
|
1164
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1165
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1166
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1167
|
+
<span class='kw'>end</span>
|
1297
1168
|
<span class='kw'>end</span></pre>
|
1298
1169
|
</td>
|
1299
1170
|
</tr>
|
@@ -1460,36 +1331,7 @@
|
|
1460
1331
|
133
|
1461
1332
|
134
|
1462
1333
|
135
|
1463
|
-
136
|
1464
|
-
137
|
1465
|
-
138
|
1466
|
-
139
|
1467
|
-
140
|
1468
|
-
141
|
1469
|
-
142
|
1470
|
-
143
|
1471
|
-
144
|
1472
|
-
145
|
1473
|
-
146
|
1474
|
-
147
|
1475
|
-
148
|
1476
|
-
149
|
1477
|
-
150
|
1478
|
-
151
|
1479
|
-
152
|
1480
|
-
153
|
1481
|
-
154
|
1482
|
-
155
|
1483
|
-
156
|
1484
|
-
157
|
1485
|
-
158
|
1486
|
-
159
|
1487
|
-
160
|
1488
|
-
161
|
1489
|
-
162
|
1490
|
-
163
|
1491
|
-
164
|
1492
|
-
165</pre>
|
1334
|
+
136</pre>
|
1493
1335
|
</td>
|
1494
1336
|
<td>
|
1495
1337
|
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 20</span>
|
@@ -1501,19 +1343,54 @@
|
|
1501
1343
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:options</span>
|
1502
1344
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:block</span>
|
1503
1345
|
|
1504
|
-
<span class='
|
1346
|
+
<span class='comment'># Class methods
|
1347
|
+
</span> <span class='kw'>class</span> <span class='op'><<</span> <span class='kw'>self</span>
|
1348
|
+
<span class='comment'># Creates a new rule.
|
1349
|
+
</span> <span class='comment'>#
|
1350
|
+
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1351
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
1352
|
+
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1353
|
+
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1354
|
+
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1355
|
+
</span> <span class='comment'># @return [Rule] The new rule.
|
1356
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1357
|
+
<span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1358
|
+
<span class='kw'>end</span>
|
1359
|
+
|
1360
|
+
<span class='comment'># Converts a class to the correspondent symbol.
|
1361
|
+
</span> <span class='comment'>#
|
1362
|
+
</span> <span class='comment'># @param klass [Class] The class to convert.
|
1363
|
+
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
1364
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1365
|
+
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
1366
|
+
<span class='kw'>end</span>
|
1367
|
+
|
1368
|
+
<span class='comment'># Converts a symbol to the correspondent DNS resource class.
|
1369
|
+
</span> <span class='comment'>#
|
1370
|
+
</span> <span class='comment'># @param symbol [Symbol] The symbol to convert.
|
1371
|
+
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
1372
|
+
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
1373
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1374
|
+
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
1375
|
+
|
1376
|
+
<span class='kw'>begin</span>
|
1377
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
1378
|
+
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
1379
|
+
<span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1380
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_resource'>rule_invalid_resource</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1381
|
+
<span class='kw'>end</span>
|
1382
|
+
<span class='kw'>end</span>
|
1383
|
+
<span class='kw'>end</span>
|
1505
1384
|
|
1506
1385
|
<span class='comment'># Creates a new rule.
|
1507
1386
|
</span> <span class='comment'>#
|
1508
1387
|
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1509
|
-
</span> <span class='comment'># @param reply [String] The IP or hostname to reply back to the client.
|
1388
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
1510
1389
|
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1511
1390
|
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1512
1391
|
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1513
1392
|
</span> <span class='comment'># @see .create
|
1514
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='
|
1515
|
-
<span class='id identifier rubyid_i18n_setup'>i18n_setup</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1516
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span>
|
1393
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1517
1394
|
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1518
1395
|
<span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1519
1396
|
<span class='kw'>end</span>
|
@@ -1522,123 +1399,59 @@
|
|
1522
1399
|
</span> <span class='comment'>#
|
1523
1400
|
</span> <span class='comment'># @return [Array|Class] The class(es) for the current rule.
|
1524
1401
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class'>resource_class</span>
|
1525
|
-
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='
|
1402
|
+
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_cls'>cls</span><span class='op'>|</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_cls'>cls</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1526
1403
|
<span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='op'>?</span> <span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span> <span class='op'>:</span> <span class='id identifier rubyid_classes'>classes</span>
|
1527
1404
|
<span class='kw'>end</span>
|
1528
1405
|
|
1529
1406
|
<span class='comment'># Checks if the rule is a regexp.
|
1530
1407
|
</span> <span class='comment'>#
|
1531
1408
|
</span> <span class='comment'># @return [Boolean] `true` if the rule is a Regexp, `false` otherwise.
|
1532
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
1409
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_regexp?'>regexp?</span>
|
1533
1410
|
<span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span>
|
1534
1411
|
<span class='kw'>end</span>
|
1412
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:is_regexp?</span><span class='comma'>,</span> <span class='symbol'>:regexp?</span>
|
1535
1413
|
|
1536
1414
|
<span class='comment'># Checks if the rule is a regexp.
|
1537
1415
|
</span> <span class='comment'>#
|
1538
1416
|
</span> <span class='comment'># @return [Boolean] `true` if the rule has a block, `false` otherwise.
|
1539
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
1417
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_block?'>block?</span>
|
1540
1418
|
<span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
1541
1419
|
<span class='kw'>end</span>
|
1420
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:has_block?</span><span class='comma'>,</span> <span class='symbol'>:block?</span>
|
1542
1421
|
|
1543
1422
|
<span class='comment'># Matches a hostname to the rule.
|
1544
1423
|
</span> <span class='comment'>#
|
1545
1424
|
</span> <span class='comment'># @param hostname [String] The hostname to match.
|
1546
1425
|
</span> <span class='comment'># @return [MatchData|Boolean|Nil] Return `true` or MatchData (if the pattern is a regexp) if the rule matches, `false` or `nil` otherwise.
|
1547
1426
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_match_host'>match_host</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
1548
|
-
<span class='id identifier
|
1427
|
+
<span class='id identifier rubyid_regexp?'>regexp?</span> <span class='op'>?</span> <span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='lparen'>(</span><span class='ivar'>@match</span> <span class='op'>==</span> <span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
1549
1428
|
<span class='kw'>end</span>
|
1550
1429
|
|
1551
|
-
<span class='
|
1552
|
-
</span> <span class='comment'>#
|
1553
|
-
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1554
|
-
</span> <span class='comment'># @param reply_or_type [String|Symbol] The IP or hostname to reply back to the client (or the type of request to match, if a block is provided).
|
1555
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match. This is ignored if a block is provided.
|
1556
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1557
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
1558
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
1559
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1560
|
-
<span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='kw'>nil</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1561
|
-
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1562
|
-
<span class='kw'>end</span>
|
1563
|
-
|
1564
|
-
<span class='comment'># Converts a class to the correspondent symbol.
|
1565
|
-
</span> <span class='comment'>#
|
1566
|
-
</span> <span class='comment'># @param klass [Class] The class to convert.
|
1567
|
-
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
1568
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1569
|
-
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
1570
|
-
<span class='kw'>end</span>
|
1430
|
+
<span class='id identifier rubyid_private'>private</span>
|
1571
1431
|
|
1572
|
-
<span class='comment'>#
|
1573
|
-
</span> <span class='
|
1574
|
-
</span>
|
1575
|
-
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
1576
|
-
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
1577
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1578
|
-
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
1579
|
-
|
1580
|
-
<span class='kw'>begin</span>
|
1581
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
1582
|
-
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
1583
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_invalid_class'>invalid_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1584
|
-
<span class='kw'>end</span>
|
1585
|
-
<span class='kw'>end</span>
|
1432
|
+
<span class='comment'># :nodoc:
|
1433
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1434
|
+
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
1586
1435
|
|
1587
|
-
|
1588
|
-
|
1589
|
-
</span>
|
1590
|
-
</span>
|
1591
|
-
</span>
|
1592
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1593
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1594
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1595
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1596
|
-
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
1436
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='comment'># reply acts like a type, type is ignored
|
1437
|
+
</span> <span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1438
|
+
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1439
|
+
<span class='kw'>else</span> <span class='comment'># reply acts like a reply
|
1440
|
+
</span> <span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
1597
1441
|
<span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1598
|
-
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
|
1599
|
-
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1600
|
-
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1601
|
-
<span class='kw'>end</span>
|
1602
|
-
|
1603
|
-
<span class='comment'># Validates a newly created rule.
|
1604
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1605
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1606
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1607
1442
|
<span class='kw'>end</span>
|
1608
1443
|
|
1609
|
-
<span class='
|
1610
|
-
</span>
|
1611
|
-
</span>
|
1612
|
-
</span>
|
1613
|
-
|
1614
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1615
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
1616
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
1617
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1618
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1619
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_block'>block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1620
|
-
|
1621
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='kw'>then</span> <span class='comment'># reply_or_type acts like a type, type is ignored
|
1622
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1623
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1624
|
-
<span class='kw'>else</span> <span class='comment'># reply_or_type acts like a reply
|
1625
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
1626
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1627
|
-
<span class='kw'>end</span>
|
1628
|
-
|
1629
|
-
<span class='id identifier rubyid_rv'>rv</span>
|
1630
|
-
<span class='kw'>end</span>
|
1444
|
+
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1445
|
+
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1446
|
+
<span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='symbol'>:en</span>
|
1447
|
+
<span class='ivar'>@i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1448
|
+
<span class='kw'>end</span>
|
1631
1449
|
|
1632
|
-
|
1633
|
-
</span>
|
1634
|
-
</span>
|
1635
|
-
</span>
|
1636
|
-
|
1637
|
-
</span> <span class='comment'># @param localizer [Localizer] A localizer object.
|
1638
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='id identifier rubyid_localizer'>localizer</span><span class='rparen'>)</span>
|
1639
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1640
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1641
|
-
<span class='kw'>end</span>
|
1450
|
+
<span class='comment'># Validates a newly created rule.
|
1451
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1452
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1453
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1454
|
+
<span class='kw'>end</span>
|
1642
1455
|
<span class='kw'>end</span></pre>
|
1643
1456
|
</td>
|
1644
1457
|
</tr>
|
@@ -1805,36 +1618,7 @@
|
|
1805
1618
|
133
|
1806
1619
|
134
|
1807
1620
|
135
|
1808
|
-
136
|
1809
|
-
137
|
1810
|
-
138
|
1811
|
-
139
|
1812
|
-
140
|
1813
|
-
141
|
1814
|
-
142
|
1815
|
-
143
|
1816
|
-
144
|
1817
|
-
145
|
1818
|
-
146
|
1819
|
-
147
|
1820
|
-
148
|
1821
|
-
149
|
1822
|
-
150
|
1823
|
-
151
|
1824
|
-
152
|
1825
|
-
153
|
1826
|
-
154
|
1827
|
-
155
|
1828
|
-
156
|
1829
|
-
157
|
1830
|
-
158
|
1831
|
-
159
|
1832
|
-
160
|
1833
|
-
161
|
1834
|
-
162
|
1835
|
-
163
|
1836
|
-
164
|
1837
|
-
165</pre>
|
1621
|
+
136</pre>
|
1838
1622
|
</td>
|
1839
1623
|
<td>
|
1840
1624
|
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 20</span>
|
@@ -1846,19 +1630,54 @@
|
|
1846
1630
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:options</span>
|
1847
1631
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:block</span>
|
1848
1632
|
|
1849
|
-
<span class='
|
1633
|
+
<span class='comment'># Class methods
|
1634
|
+
</span> <span class='kw'>class</span> <span class='op'><<</span> <span class='kw'>self</span>
|
1635
|
+
<span class='comment'># Creates a new rule.
|
1636
|
+
</span> <span class='comment'>#
|
1637
|
+
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1638
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
1639
|
+
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1640
|
+
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1641
|
+
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1642
|
+
</span> <span class='comment'># @return [Rule] The new rule.
|
1643
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1644
|
+
<span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1645
|
+
<span class='kw'>end</span>
|
1646
|
+
|
1647
|
+
<span class='comment'># Converts a class to the correspondent symbol.
|
1648
|
+
</span> <span class='comment'>#
|
1649
|
+
</span> <span class='comment'># @param klass [Class] The class to convert.
|
1650
|
+
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
1651
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1652
|
+
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
1653
|
+
<span class='kw'>end</span>
|
1654
|
+
|
1655
|
+
<span class='comment'># Converts a symbol to the correspondent DNS resource class.
|
1656
|
+
</span> <span class='comment'>#
|
1657
|
+
</span> <span class='comment'># @param symbol [Symbol] The symbol to convert.
|
1658
|
+
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
1659
|
+
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
1660
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1661
|
+
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
1662
|
+
|
1663
|
+
<span class='kw'>begin</span>
|
1664
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
1665
|
+
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
1666
|
+
<span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1667
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_resource'>rule_invalid_resource</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1668
|
+
<span class='kw'>end</span>
|
1669
|
+
<span class='kw'>end</span>
|
1670
|
+
<span class='kw'>end</span>
|
1850
1671
|
|
1851
1672
|
<span class='comment'># Creates a new rule.
|
1852
1673
|
</span> <span class='comment'>#
|
1853
1674
|
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1854
|
-
</span> <span class='comment'># @param reply [String] The IP or hostname to reply back to the client.
|
1675
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
1855
1676
|
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1856
1677
|
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1857
1678
|
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1858
1679
|
</span> <span class='comment'># @see .create
|
1859
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='
|
1860
|
-
<span class='id identifier rubyid_i18n_setup'>i18n_setup</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1861
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span>
|
1680
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1862
1681
|
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1863
1682
|
<span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1864
1683
|
<span class='kw'>end</span>
|
@@ -1867,123 +1686,59 @@
|
|
1867
1686
|
</span> <span class='comment'>#
|
1868
1687
|
</span> <span class='comment'># @return [Array|Class] The class(es) for the current rule.
|
1869
1688
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class'>resource_class</span>
|
1870
|
-
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='
|
1689
|
+
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_cls'>cls</span><span class='op'>|</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_cls'>cls</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1871
1690
|
<span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='op'>?</span> <span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span> <span class='op'>:</span> <span class='id identifier rubyid_classes'>classes</span>
|
1872
1691
|
<span class='kw'>end</span>
|
1873
1692
|
|
1874
1693
|
<span class='comment'># Checks if the rule is a regexp.
|
1875
1694
|
</span> <span class='comment'>#
|
1876
1695
|
</span> <span class='comment'># @return [Boolean] `true` if the rule is a Regexp, `false` otherwise.
|
1877
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
1696
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_regexp?'>regexp?</span>
|
1878
1697
|
<span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span>
|
1879
1698
|
<span class='kw'>end</span>
|
1699
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:is_regexp?</span><span class='comma'>,</span> <span class='symbol'>:regexp?</span>
|
1880
1700
|
|
1881
1701
|
<span class='comment'># Checks if the rule is a regexp.
|
1882
1702
|
</span> <span class='comment'>#
|
1883
1703
|
</span> <span class='comment'># @return [Boolean] `true` if the rule has a block, `false` otherwise.
|
1884
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
1704
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_block?'>block?</span>
|
1885
1705
|
<span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
1886
1706
|
<span class='kw'>end</span>
|
1707
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:has_block?</span><span class='comma'>,</span> <span class='symbol'>:block?</span>
|
1887
1708
|
|
1888
1709
|
<span class='comment'># Matches a hostname to the rule.
|
1889
1710
|
</span> <span class='comment'>#
|
1890
1711
|
</span> <span class='comment'># @param hostname [String] The hostname to match.
|
1891
1712
|
</span> <span class='comment'># @return [MatchData|Boolean|Nil] Return `true` or MatchData (if the pattern is a regexp) if the rule matches, `false` or `nil` otherwise.
|
1892
1713
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_match_host'>match_host</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
1893
|
-
<span class='id identifier
|
1714
|
+
<span class='id identifier rubyid_regexp?'>regexp?</span> <span class='op'>?</span> <span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='lparen'>(</span><span class='ivar'>@match</span> <span class='op'>==</span> <span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
1894
1715
|
<span class='kw'>end</span>
|
1895
1716
|
|
1896
|
-
<span class='
|
1897
|
-
</span> <span class='comment'>#
|
1898
|
-
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1899
|
-
</span> <span class='comment'># @param reply_or_type [String|Symbol] The IP or hostname to reply back to the client (or the type of request to match, if a block is provided).
|
1900
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match. This is ignored if a block is provided.
|
1901
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1902
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
1903
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
1904
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1905
|
-
<span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='kw'>nil</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1906
|
-
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1907
|
-
<span class='kw'>end</span>
|
1908
|
-
|
1909
|
-
<span class='comment'># Converts a class to the correspondent symbol.
|
1910
|
-
</span> <span class='comment'>#
|
1911
|
-
</span> <span class='comment'># @param klass [Class] The class to convert.
|
1912
|
-
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
1913
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1914
|
-
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
1915
|
-
<span class='kw'>end</span>
|
1717
|
+
<span class='id identifier rubyid_private'>private</span>
|
1916
1718
|
|
1917
|
-
<span class='comment'>#
|
1918
|
-
</span> <span class='
|
1919
|
-
</span>
|
1920
|
-
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
1921
|
-
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
1922
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1923
|
-
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
1924
|
-
|
1925
|
-
<span class='kw'>begin</span>
|
1926
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
1927
|
-
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
1928
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_invalid_class'>invalid_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1929
|
-
<span class='kw'>end</span>
|
1930
|
-
<span class='kw'>end</span>
|
1719
|
+
<span class='comment'># :nodoc:
|
1720
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1721
|
+
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
1931
1722
|
|
1932
|
-
|
1933
|
-
|
1934
|
-
</span>
|
1935
|
-
</span>
|
1936
|
-
</span>
|
1937
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1938
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1939
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1940
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1941
|
-
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
1723
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='comment'># reply acts like a type, type is ignored
|
1724
|
+
</span> <span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1725
|
+
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1726
|
+
<span class='kw'>else</span> <span class='comment'># reply acts like a reply
|
1727
|
+
</span> <span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
1942
1728
|
<span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1943
|
-
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
|
1944
|
-
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1945
|
-
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1946
|
-
<span class='kw'>end</span>
|
1947
|
-
|
1948
|
-
<span class='comment'># Validates a newly created rule.
|
1949
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1950
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1951
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1952
1729
|
<span class='kw'>end</span>
|
1953
1730
|
|
1954
|
-
<span class='
|
1955
|
-
</span>
|
1956
|
-
</span>
|
1957
|
-
</span>
|
1958
|
-
|
1959
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1960
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
1961
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
1962
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1963
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1964
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_block'>block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1965
|
-
|
1966
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='kw'>then</span> <span class='comment'># reply_or_type acts like a type, type is ignored
|
1967
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1968
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1969
|
-
<span class='kw'>else</span> <span class='comment'># reply_or_type acts like a reply
|
1970
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
1971
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
1972
|
-
<span class='kw'>end</span>
|
1973
|
-
|
1974
|
-
<span class='id identifier rubyid_rv'>rv</span>
|
1975
|
-
<span class='kw'>end</span>
|
1731
|
+
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
1732
|
+
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
1733
|
+
<span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='symbol'>:en</span>
|
1734
|
+
<span class='ivar'>@i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1735
|
+
<span class='kw'>end</span>
|
1976
1736
|
|
1977
|
-
|
1978
|
-
</span>
|
1979
|
-
</span>
|
1980
|
-
</span>
|
1981
|
-
|
1982
|
-
</span> <span class='comment'># @param localizer [Localizer] A localizer object.
|
1983
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='id identifier rubyid_localizer'>localizer</span><span class='rparen'>)</span>
|
1984
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1985
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1986
|
-
<span class='kw'>end</span>
|
1737
|
+
<span class='comment'># Validates a newly created rule.
|
1738
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
1739
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1740
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
1741
|
+
<span class='kw'>end</span>
|
1987
1742
|
<span class='kw'>end</span></pre>
|
1988
1743
|
</td>
|
1989
1744
|
</tr>
|
@@ -2150,36 +1905,7 @@
|
|
2150
1905
|
133
|
2151
1906
|
134
|
2152
1907
|
135
|
2153
|
-
136
|
2154
|
-
137
|
2155
|
-
138
|
2156
|
-
139
|
2157
|
-
140
|
2158
|
-
141
|
2159
|
-
142
|
2160
|
-
143
|
2161
|
-
144
|
2162
|
-
145
|
2163
|
-
146
|
2164
|
-
147
|
2165
|
-
148
|
2166
|
-
149
|
2167
|
-
150
|
2168
|
-
151
|
2169
|
-
152
|
2170
|
-
153
|
2171
|
-
154
|
2172
|
-
155
|
2173
|
-
156
|
2174
|
-
157
|
2175
|
-
158
|
2176
|
-
159
|
2177
|
-
160
|
2178
|
-
161
|
2179
|
-
162
|
2180
|
-
163
|
2181
|
-
164
|
2182
|
-
165</pre>
|
1908
|
+
136</pre>
|
2183
1909
|
</td>
|
2184
1910
|
<td>
|
2185
1911
|
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 20</span>
|
@@ -2191,19 +1917,54 @@
|
|
2191
1917
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:options</span>
|
2192
1918
|
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:block</span>
|
2193
1919
|
|
2194
|
-
<span class='
|
1920
|
+
<span class='comment'># Class methods
|
1921
|
+
</span> <span class='kw'>class</span> <span class='op'><<</span> <span class='kw'>self</span>
|
1922
|
+
<span class='comment'># Creates a new rule.
|
1923
|
+
</span> <span class='comment'>#
|
1924
|
+
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
1925
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
1926
|
+
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
1927
|
+
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
1928
|
+
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
1929
|
+
</span> <span class='comment'># @return [Rule] The new rule.
|
1930
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1931
|
+
<span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1932
|
+
<span class='kw'>end</span>
|
1933
|
+
|
1934
|
+
<span class='comment'># Converts a class to the correspondent symbol.
|
1935
|
+
</span> <span class='comment'>#
|
1936
|
+
</span> <span class='comment'># @param klass [Class] The class to convert.
|
1937
|
+
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
1938
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1939
|
+
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
1940
|
+
<span class='kw'>end</span>
|
1941
|
+
|
1942
|
+
<span class='comment'># Converts a symbol to the correspondent DNS resource class.
|
1943
|
+
</span> <span class='comment'>#
|
1944
|
+
</span> <span class='comment'># @param symbol [Symbol] The symbol to convert.
|
1945
|
+
</span> <span class='comment'># @param locale [Symbol] The locale to use for the messages.
|
1946
|
+
</span> <span class='comment'># @return [Symbol] The class associated to the symbol.
|
1947
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1948
|
+
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
1949
|
+
|
1950
|
+
<span class='kw'>begin</span>
|
1951
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
1952
|
+
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
1953
|
+
<span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1954
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_resource'>rule_invalid_resource</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1955
|
+
<span class='kw'>end</span>
|
1956
|
+
<span class='kw'>end</span>
|
1957
|
+
<span class='kw'>end</span>
|
2195
1958
|
|
2196
1959
|
<span class='comment'># Creates a new rule.
|
2197
1960
|
</span> <span class='comment'>#
|
2198
1961
|
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
2199
|
-
</span> <span class='comment'># @param reply [String] The IP or hostname to reply back to the client.
|
1962
|
+
</span> <span class='comment'># @param reply [String|Symbol] The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.
|
2200
1963
|
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
2201
1964
|
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
2202
1965
|
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
2203
1966
|
</span> <span class='comment'># @see .create
|
2204
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='
|
2205
|
-
<span class='id identifier rubyid_i18n_setup'>i18n_setup</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
2206
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span>
|
1967
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2207
1968
|
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2208
1969
|
<span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
2209
1970
|
<span class='kw'>end</span>
|
@@ -2212,123 +1973,59 @@
|
|
2212
1973
|
</span> <span class='comment'>#
|
2213
1974
|
</span> <span class='comment'># @return [Array|Class] The class(es) for the current rule.
|
2214
1975
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_resource_class'>resource_class</span>
|
2215
|
-
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='
|
1976
|
+
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_cls'>cls</span><span class='op'>|</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_cls'>cls</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
2216
1977
|
<span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='op'>?</span> <span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span> <span class='op'>:</span> <span class='id identifier rubyid_classes'>classes</span>
|
2217
1978
|
<span class='kw'>end</span>
|
2218
1979
|
|
2219
1980
|
<span class='comment'># Checks if the rule is a regexp.
|
2220
1981
|
</span> <span class='comment'>#
|
2221
1982
|
</span> <span class='comment'># @return [Boolean] `true` if the rule is a Regexp, `false` otherwise.
|
2222
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
1983
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_regexp?'>regexp?</span>
|
2223
1984
|
<span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span>
|
2224
1985
|
<span class='kw'>end</span>
|
1986
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:is_regexp?</span><span class='comma'>,</span> <span class='symbol'>:regexp?</span>
|
2225
1987
|
|
2226
1988
|
<span class='comment'># Checks if the rule is a regexp.
|
2227
1989
|
</span> <span class='comment'>#
|
2228
1990
|
</span> <span class='comment'># @return [Boolean] `true` if the rule has a block, `false` otherwise.
|
2229
|
-
</span> <span class='kw'>def</span> <span class='id identifier
|
1991
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_block?'>block?</span>
|
2230
1992
|
<span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
2231
1993
|
<span class='kw'>end</span>
|
1994
|
+
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:has_block?</span><span class='comma'>,</span> <span class='symbol'>:block?</span>
|
2232
1995
|
|
2233
1996
|
<span class='comment'># Matches a hostname to the rule.
|
2234
1997
|
</span> <span class='comment'>#
|
2235
1998
|
</span> <span class='comment'># @param hostname [String] The hostname to match.
|
2236
1999
|
</span> <span class='comment'># @return [MatchData|Boolean|Nil] Return `true` or MatchData (if the pattern is a regexp) if the rule matches, `false` or `nil` otherwise.
|
2237
2000
|
</span> <span class='kw'>def</span> <span class='id identifier rubyid_match_host'>match_host</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
2238
|
-
<span class='id identifier
|
2001
|
+
<span class='id identifier rubyid_regexp?'>regexp?</span> <span class='op'>?</span> <span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='lparen'>(</span><span class='ivar'>@match</span> <span class='op'>==</span> <span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
2239
2002
|
<span class='kw'>end</span>
|
2240
2003
|
|
2241
|
-
<span class='
|
2242
|
-
</span> <span class='comment'>#
|
2243
|
-
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
2244
|
-
</span> <span class='comment'># @param reply_or_type [String|Symbol] The IP or hostname to reply back to the client (or the type of request to match, if a block is provided).
|
2245
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match. This is ignored if a block is provided.
|
2246
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
2247
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
2248
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
2249
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2250
|
-
<span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='kw'>nil</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
2251
|
-
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2252
|
-
<span class='kw'>end</span>
|
2004
|
+
<span class='id identifier rubyid_private'>private</span>
|
2253
2005
|
|
2254
|
-
<span class='comment'>#
|
2255
|
-
</span> <span class='
|
2256
|
-
</span>
|
2257
|
-
</span> <span class='comment'># @return [Symbol] The symbol representation of the class.
|
2258
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
2259
|
-
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
2260
|
-
<span class='kw'>end</span>
|
2006
|
+
<span class='comment'># :nodoc:
|
2007
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2008
|
+
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
2261
2009
|
|
2262
|
-
|
2263
|
-
</span>
|
2264
|
-
</span>
|
2265
|
-
</span>
|
2266
|
-
</span>
|
2267
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
2268
|
-
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
2269
|
-
|
2270
|
-
<span class='kw'>begin</span>
|
2271
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
2272
|
-
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
2273
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:devdnsd</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_invalid_class'>invalid_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
2274
|
-
<span class='kw'>end</span>
|
2275
|
-
<span class='kw'>end</span>
|
2276
|
-
|
2277
|
-
<span class='id identifier rubyid_private'>private</span>
|
2278
|
-
<span class='comment'># Setups a new rule.
|
2279
|
-
</span> <span class='comment'>#
|
2280
|
-
</span> <span class='comment'># @param match [String|Regexp] The pattern to match.
|
2281
|
-
</span> <span class='comment'># @param reply [String] The IP or hostname to reply back to the client.
|
2282
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match.
|
2283
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
2284
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
|
2285
|
-
</span> <span class='kw'>def</span> <span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2286
|
-
<span class='ivar'>@match</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>
|
2010
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='comment'># reply acts like a type, type is ignored
|
2011
|
+
</span> <span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
2012
|
+
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
2013
|
+
<span class='kw'>else</span> <span class='comment'># reply acts like a reply
|
2014
|
+
</span> <span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
2287
2015
|
<span class='ivar'>@type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
2288
|
-
<span class='ivar'>@reply</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
|
2289
|
-
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
2290
|
-
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
2291
2016
|
<span class='kw'>end</span>
|
2292
2017
|
|
2293
|
-
<span class='
|
2294
|
-
</span>
|
2295
|
-
|
2296
|
-
|
2297
|
-
|
2298
|
-
|
2299
|
-
<span class='comment'># Setups a new rule.
|
2300
|
-
</span> <span class='comment'>#
|
2301
|
-
</span> <span class='comment'># @param rv [Rule] The rule that is been created.
|
2302
|
-
</span> <span class='comment'># @param reply_or_type [String|Symbol] The IP or hostname to reply back to the client (or the type of request to match, if a block is provided).
|
2303
|
-
</span> <span class='comment'># @param type [Symbol] The type of request to match. This is ignored if a block is provided.
|
2304
|
-
</span> <span class='comment'># @param options [Hash] A list of options for the request.
|
2305
|
-
</span> <span class='comment'># @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
|
2306
|
-
</span> <span class='comment'># @return [Rule] The new rule.
|
2307
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2308
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
2309
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_block'>block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
2310
|
-
|
2311
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='kw'>then</span> <span class='comment'># reply_or_type acts like a type, type is ignored
|
2312
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
2313
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
2314
|
-
<span class='kw'>else</span> <span class='comment'># reply_or_type acts like a reply
|
2315
|
-
</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_reply'>reply</span> <span class='op'>=</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span>
|
2316
|
-
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>||</span> <span class='symbol'>:A</span>
|
2317
|
-
<span class='kw'>end</span>
|
2318
|
-
|
2319
|
-
<span class='id identifier rubyid_rv'>rv</span>
|
2320
|
-
<span class='kw'>end</span>
|
2018
|
+
<span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span>
|
2019
|
+
<span class='ivar'>@block</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
|
2020
|
+
<span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='symbol'>:en</span>
|
2021
|
+
<span class='ivar'>@i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
2022
|
+
<span class='kw'>end</span>
|
2321
2023
|
|
2322
|
-
|
2323
|
-
</span>
|
2324
|
-
</span>
|
2325
|
-
</span>
|
2326
|
-
|
2327
|
-
</span> <span class='comment'># @param localizer [Localizer] A localizer object.
|
2328
|
-
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_validate_options'>validate_options</span><span class='lparen'>(</span><span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='comma'>,</span> <span class='id identifier rubyid_localizer'>localizer</span><span class='rparen'>)</span>
|
2329
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
2330
|
-
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_localizer'>localizer</span><span class='period'>.</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
2331
|
-
<span class='kw'>end</span>
|
2024
|
+
<span class='comment'># Validates a newly created rule.
|
2025
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_validate_rule'>validate_rule</span>
|
2026
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_call'>rule_invalid_call</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>&&</span> <span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
2027
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='ivar'>@i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_options'>rule_invalid_options</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
2028
|
+
<span class='kw'>end</span>
|
2332
2029
|
<span class='kw'>end</span></pre>
|
2333
2030
|
</td>
|
2334
2031
|
</tr>
|
@@ -2345,7 +2042,7 @@
|
|
2345
2042
|
<div class="method_details first">
|
2346
2043
|
<h3 class="signature first" id="create-class_method">
|
2347
2044
|
|
2348
|
-
+ (<tt><span class='object_link'><a href="" title="DevDNSd::Rule (class)">Rule</a></span></tt>) <strong>create</strong>(match
|
2045
|
+
+ (<tt><span class='object_link'><a href="" title="DevDNSd::Rule (class)">Rule</a></span></tt>) <strong>create</strong>(match: /.+/, reply: "127.0.0.1", type: :A, options: {}, &block)
|
2349
2046
|
|
2350
2047
|
|
2351
2048
|
|
@@ -2379,17 +2076,15 @@
|
|
2379
2076
|
|
2380
2077
|
<li>
|
2381
2078
|
|
2382
|
-
<span class='name'>
|
2079
|
+
<span class='name'>reply</span>
|
2383
2080
|
|
2384
2081
|
|
2385
2082
|
<span class='type'>(<tt>String|Symbol</tt>)</span>
|
2386
2083
|
|
2387
2084
|
|
2388
|
-
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
2389
|
-
|
2390
2085
|
|
2391
2086
|
—
|
2392
|
-
<div class='inline'><p>The IP or hostname to reply back to the client
|
2087
|
+
<div class='inline'><p>The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.</p>
|
2393
2088
|
</div>
|
2394
2089
|
|
2395
2090
|
</li>
|
@@ -2402,11 +2097,9 @@
|
|
2402
2097
|
<span class='type'>(<tt>Symbol</tt>)</span>
|
2403
2098
|
|
2404
2099
|
|
2405
|
-
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
2406
|
-
|
2407
2100
|
|
2408
2101
|
—
|
2409
|
-
<div class='inline'><p>The type of request to match
|
2102
|
+
<div class='inline'><p>The type of request to match.</p>
|
2410
2103
|
</div>
|
2411
2104
|
|
2412
2105
|
</li>
|
@@ -2419,8 +2112,6 @@
|
|
2419
2112
|
<span class='type'>(<tt>Hash</tt>)</span>
|
2420
2113
|
|
2421
2114
|
|
2422
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
2423
|
-
|
2424
2115
|
|
2425
2116
|
—
|
2426
2117
|
<div class='inline'><p>A list of options for the request.</p>
|
@@ -2438,7 +2129,7 @@
|
|
2438
2129
|
|
2439
2130
|
|
2440
2131
|
—
|
2441
|
-
<div class='inline'><p>An optional block to compute the reply instead of using the <code>
|
2132
|
+
<div class='inline'><p>An optional block to compute the reply instead of using the <code>reply</code> parameter.</p>
|
2442
2133
|
</div>
|
2443
2134
|
|
2444
2135
|
</li>
|
@@ -2469,17 +2160,15 @@
|
|
2469
2160
|
<pre class="lines">
|
2470
2161
|
|
2471
2162
|
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
85</pre>
|
2163
|
+
37
|
2164
|
+
38
|
2165
|
+
39</pre>
|
2476
2166
|
</td>
|
2477
2167
|
<td>
|
2478
|
-
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line
|
2168
|
+
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 37</span>
|
2479
2169
|
|
2480
|
-
<span class='kw'>def</span> <span class='
|
2481
|
-
<span class='id identifier
|
2482
|
-
<span class='id identifier rubyid_setup'>setup</span><span class='lparen'>(</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_reply_or_type'>reply_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2170
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>.+</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='symbol'>:A</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2171
|
+
<span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>match:</span> <span class='id identifier rubyid_match'>match</span><span class='comma'>,</span> <span class='label'>reply:</span> <span class='id identifier rubyid_reply'>reply</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2483
2172
|
<span class='kw'>end</span></pre>
|
2484
2173
|
</td>
|
2485
2174
|
</tr>
|
@@ -2547,14 +2236,14 @@
|
|
2547
2236
|
<pre class="lines">
|
2548
2237
|
|
2549
2238
|
|
2550
|
-
|
2551
|
-
|
2552
|
-
|
2239
|
+
45
|
2240
|
+
46
|
2241
|
+
47</pre>
|
2553
2242
|
</td>
|
2554
2243
|
<td>
|
2555
|
-
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line
|
2244
|
+
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 45</span>
|
2556
2245
|
|
2557
|
-
<span class='kw'>def</span> <span class='
|
2246
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_resource_class_to_symbol'>resource_class_to_symbol</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
2558
2247
|
<span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+::)?(.+)</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
2559
2248
|
<span class='kw'>end</span></pre>
|
2560
2249
|
</td>
|
@@ -2640,26 +2329,28 @@
|
|
2640
2329
|
<pre class="lines">
|
2641
2330
|
|
2642
2331
|
|
2643
|
-
|
2644
|
-
|
2645
|
-
|
2646
|
-
|
2647
|
-
|
2648
|
-
|
2649
|
-
|
2650
|
-
|
2651
|
-
|
2332
|
+
54
|
2333
|
+
55
|
2334
|
+
56
|
2335
|
+
57
|
2336
|
+
58
|
2337
|
+
59
|
2338
|
+
60
|
2339
|
+
61
|
2340
|
+
62
|
2341
|
+
63</pre>
|
2652
2342
|
</td>
|
2653
2343
|
<td>
|
2654
|
-
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line
|
2344
|
+
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 54</span>
|
2655
2345
|
|
2656
|
-
<span class='kw'>def</span> <span class='
|
2346
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
2657
2347
|
<span class='id identifier rubyid_symbol'>symbol</span> <span class='op'>=</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
|
2658
2348
|
|
2659
2349
|
<span class='kw'>begin</span>
|
2660
2350
|
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Resolv::DNS::Resource::IN::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
2661
2351
|
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>NameError</span>
|
2662
|
-
<span class='id identifier
|
2352
|
+
<span class='id identifier rubyid_i18n'>i18n</span> <span class='op'>=</span> <span class='const'>Bovem</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>devdnsd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>path:</span> <span class='op'>::</span><span class='const'>Pathname</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='kw'>__FILE__</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/../../locales/</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
2353
|
+
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>DevDNSd</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>InvalidRule</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_rule_invalid_resource'>rule_invalid_resource</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
2663
2354
|
<span class='kw'>end</span>
|
2664
2355
|
<span class='kw'>end</span></pre>
|
2665
2356
|
</td>
|
@@ -2674,12 +2365,16 @@
|
|
2674
2365
|
|
2675
2366
|
|
2676
2367
|
<div class="method_details first">
|
2677
|
-
<h3 class="signature first" id="
|
2368
|
+
<h3 class="signature first" id="block?-instance_method">
|
2678
2369
|
|
2679
|
-
- (<tt>Boolean</tt>) <strong>
|
2370
|
+
- (<tt>Boolean</tt>) <strong>block?</strong>
|
2680
2371
|
|
2681
2372
|
|
2682
2373
|
|
2374
|
+
<span class="aliases">Also known as:
|
2375
|
+
<span class="names"><span id='has_block?-instance_method'>has_block?</span></span>
|
2376
|
+
</span>
|
2377
|
+
|
2683
2378
|
|
2684
2379
|
|
2685
2380
|
</h3><div class="docstring">
|
@@ -2715,14 +2410,14 @@
|
|
2715
2410
|
<pre class="lines">
|
2716
2411
|
|
2717
2412
|
|
2718
|
-
|
2719
|
-
|
2720
|
-
|
2413
|
+
98
|
2414
|
+
99
|
2415
|
+
100</pre>
|
2721
2416
|
</td>
|
2722
2417
|
<td>
|
2723
|
-
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line
|
2418
|
+
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 98</span>
|
2724
2419
|
|
2725
|
-
<span class='kw'>def</span> <span class='id identifier
|
2420
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_block?'>block?</span>
|
2726
2421
|
<span class='ivar'>@block</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
2727
2422
|
<span class='kw'>end</span></pre>
|
2728
2423
|
</td>
|
@@ -2731,9 +2426,9 @@
|
|
2731
2426
|
</div>
|
2732
2427
|
|
2733
2428
|
<div class="method_details ">
|
2734
|
-
<h3 class="signature " id="
|
2429
|
+
<h3 class="signature " id="match_host-instance_method">
|
2735
2430
|
|
2736
|
-
- (<tt>Boolean</tt>) <strong>
|
2431
|
+
- (<tt>MatchData|Boolean|Nil</tt>) <strong>match_host</strong>(hostname)
|
2737
2432
|
|
2738
2433
|
|
2739
2434
|
|
@@ -2741,25 +2436,44 @@
|
|
2741
2436
|
|
2742
2437
|
</h3><div class="docstring">
|
2743
2438
|
<div class="discussion">
|
2744
|
-
<p>
|
2439
|
+
<p>Matches a hostname to the rule.</p>
|
2745
2440
|
|
2746
2441
|
|
2747
2442
|
</div>
|
2748
2443
|
</div>
|
2749
2444
|
<div class="tags">
|
2445
|
+
<p class="tag_title">Parameters:</p>
|
2446
|
+
<ul class="param">
|
2750
2447
|
|
2448
|
+
<li>
|
2449
|
+
|
2450
|
+
<span class='name'>hostname</span>
|
2451
|
+
|
2452
|
+
|
2453
|
+
<span class='type'>(<tt>String</tt>)</span>
|
2454
|
+
|
2455
|
+
|
2456
|
+
|
2457
|
+
—
|
2458
|
+
<div class='inline'><p>The hostname to match.</p>
|
2459
|
+
</div>
|
2460
|
+
|
2461
|
+
</li>
|
2462
|
+
|
2463
|
+
</ul>
|
2464
|
+
|
2751
2465
|
<p class="tag_title">Returns:</p>
|
2752
2466
|
<ul class="return">
|
2753
2467
|
|
2754
2468
|
<li>
|
2755
2469
|
|
2756
2470
|
|
2757
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
2471
|
+
<span class='type'>(<tt>MatchData|Boolean|Nil</tt>)</span>
|
2758
2472
|
|
2759
2473
|
|
2760
2474
|
|
2761
2475
|
—
|
2762
|
-
<div class='inline'><p
|
2476
|
+
<div class='inline'><p>Return <code>true</code> or MatchData (if the pattern is a regexp) if the rule matches, <code>false</code> or <code>nil</code> otherwise.</p>
|
2763
2477
|
</div>
|
2764
2478
|
|
2765
2479
|
</li>
|
@@ -2772,15 +2486,15 @@
|
|
2772
2486
|
<pre class="lines">
|
2773
2487
|
|
2774
2488
|
|
2775
|
-
|
2776
|
-
|
2777
|
-
|
2489
|
+
107
|
2490
|
+
108
|
2491
|
+
109</pre>
|
2778
2492
|
</td>
|
2779
2493
|
<td>
|
2780
|
-
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line
|
2494
|
+
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 107</span>
|
2781
2495
|
|
2782
|
-
<span class='kw'>def</span> <span class='id identifier
|
2783
|
-
<span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier
|
2496
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_match_host'>match_host</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
2497
|
+
<span class='id identifier rubyid_regexp?'>regexp?</span> <span class='op'>?</span> <span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='lparen'>(</span><span class='ivar'>@match</span> <span class='op'>==</span> <span class='id identifier rubyid_hostname'>hostname</span><span class='rparen'>)</span>
|
2784
2498
|
<span class='kw'>end</span></pre>
|
2785
2499
|
</td>
|
2786
2500
|
</tr>
|
@@ -2788,54 +2502,39 @@
|
|
2788
2502
|
</div>
|
2789
2503
|
|
2790
2504
|
<div class="method_details ">
|
2791
|
-
<h3 class="signature " id="
|
2505
|
+
<h3 class="signature " id="regexp?-instance_method">
|
2792
2506
|
|
2793
|
-
- (<tt>
|
2507
|
+
- (<tt>Boolean</tt>) <strong>regexp?</strong>
|
2794
2508
|
|
2795
2509
|
|
2796
2510
|
|
2511
|
+
<span class="aliases">Also known as:
|
2512
|
+
<span class="names"><span id='is_regexp?-instance_method'>is_regexp?</span></span>
|
2513
|
+
</span>
|
2514
|
+
|
2797
2515
|
|
2798
2516
|
|
2799
2517
|
</h3><div class="docstring">
|
2800
2518
|
<div class="discussion">
|
2801
|
-
<p>
|
2519
|
+
<p>Checks if the rule is a regexp.</p>
|
2802
2520
|
|
2803
2521
|
|
2804
2522
|
</div>
|
2805
2523
|
</div>
|
2806
2524
|
<div class="tags">
|
2807
|
-
<p class="tag_title">Parameters:</p>
|
2808
|
-
<ul class="param">
|
2809
|
-
|
2810
|
-
<li>
|
2811
|
-
|
2812
|
-
<span class='name'>hostname</span>
|
2813
|
-
|
2814
|
-
|
2815
|
-
<span class='type'>(<tt>String</tt>)</span>
|
2816
|
-
|
2817
|
-
|
2818
|
-
|
2819
|
-
—
|
2820
|
-
<div class='inline'><p>The hostname to match.</p>
|
2821
|
-
</div>
|
2822
|
-
|
2823
|
-
</li>
|
2824
2525
|
|
2825
|
-
</ul>
|
2826
|
-
|
2827
2526
|
<p class="tag_title">Returns:</p>
|
2828
2527
|
<ul class="return">
|
2829
2528
|
|
2830
2529
|
<li>
|
2831
2530
|
|
2832
2531
|
|
2833
|
-
<span class='type'>(<tt>
|
2532
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
2834
2533
|
|
2835
2534
|
|
2836
2535
|
|
2837
2536
|
—
|
2838
|
-
<div class='inline'><p
|
2537
|
+
<div class='inline'><p><code>true</code> if the rule is a Regexp, <code>false</code> otherwise.</p>
|
2839
2538
|
</div>
|
2840
2539
|
|
2841
2540
|
</li>
|
@@ -2848,15 +2547,15 @@
|
|
2848
2547
|
<pre class="lines">
|
2849
2548
|
|
2850
2549
|
|
2851
|
-
|
2852
|
-
|
2853
|
-
|
2550
|
+
90
|
2551
|
+
91
|
2552
|
+
92</pre>
|
2854
2553
|
</td>
|
2855
2554
|
<td>
|
2856
|
-
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line
|
2555
|
+
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 90</span>
|
2857
2556
|
|
2858
|
-
<span class='kw'>def</span> <span class='id identifier
|
2859
|
-
<span class='
|
2557
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_regexp?'>regexp?</span>
|
2558
|
+
<span class='ivar'>@match</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Regexp</span><span class='rparen'>)</span>
|
2860
2559
|
<span class='kw'>end</span></pre>
|
2861
2560
|
</td>
|
2862
2561
|
</tr>
|
@@ -2905,16 +2604,16 @@
|
|
2905
2604
|
<pre class="lines">
|
2906
2605
|
|
2907
2606
|
|
2908
|
-
|
2909
|
-
|
2910
|
-
|
2911
|
-
|
2607
|
+
82
|
2608
|
+
83
|
2609
|
+
84
|
2610
|
+
85</pre>
|
2912
2611
|
</td>
|
2913
2612
|
<td>
|
2914
|
-
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line
|
2613
|
+
<pre class="code"><span class="info file"># File 'lib/devdnsd/rule.rb', line 82</span>
|
2915
2614
|
|
2916
2615
|
<span class='kw'>def</span> <span class='id identifier rubyid_resource_class'>resource_class</span>
|
2917
|
-
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='
|
2616
|
+
<span class='id identifier rubyid_classes'>classes</span> <span class='op'>=</span> <span class='ivar'>@type</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_cls'>cls</span><span class='op'>|</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_symbol_to_resource_class'>symbol_to_resource_class</span><span class='lparen'>(</span><span class='id identifier rubyid_cls'>cls</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
2918
2617
|
<span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span> <span class='op'>?</span> <span class='id identifier rubyid_classes'>classes</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span> <span class='op'>:</span> <span class='id identifier rubyid_classes'>classes</span>
|
2919
2618
|
<span class='kw'>end</span></pre>
|
2920
2619
|
</td>
|
@@ -2927,9 +2626,9 @@
|
|
2927
2626
|
</div>
|
2928
2627
|
|
2929
2628
|
<div id="footer">
|
2930
|
-
Generated on
|
2629
|
+
Generated on Wed Mar 30 19:23:43 2016 by
|
2931
2630
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
2932
|
-
0.8.7.
|
2631
|
+
0.8.7.6 (ruby-2.3.0).
|
2933
2632
|
</div>
|
2934
2633
|
|
2935
2634
|
</body>
|