Class: DNSer::Domain
- Inherits:
-
Object
- Object
- DNSer::Domain
- Defined in:
- lib/dnser/domain.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #current, #host)
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(domain_name, params = {}, &block) ⇒ Domain
constructor
A new instance of Domain.
- #method_missing(name, *args, &block) ⇒ Object
- #ttl(*args) ⇒ Object
Constructor Details
#initialize(domain_name, params = {}, &block) ⇒ Domain
Returns a new instance of Domain.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dnser/domain.rb', line 11 def initialize domain_name, params = {}, &block @name = domain_name @builder = params[:builder] || DNSer.config.output #DNSer::StreamBuilder.new($stdout) @builder = DNSer::StreamBuilder.new(@builder) unless @builder.is_a? DNSer::Builder @name = @name + '.' unless @name.end_with?('.') @ttl_val = 3600 @records = [] instance_exec self, &block if block dump end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dnser/domain.rb', line 62 def method_missing name, *args, &block name = name.to_s.downcase return DNSer.apply_template name.gsub('apply_', '') do |tpl| tpl.apply self, *args, &block end if name.start_with? 'apply_' params = args.last.dup if args.last.is_a? Hash record_class = begin eval "::DNSer::#{name.capitalize}Record" rescue NameError => e args = [name] + args DNSer::BaseRecord end record = record_class.new(self, *args, &block) @records << record if params.key? :alias [params[:alias]].flatten.each do |host| @records << DNSer::BaseRecord.new(self, :CNAME, host, record, &block) end end if params record end |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: current, host
Returns the value of attribute name.
9 10 11 |
# File 'lib/dnser/domain.rb', line 9 def name @name end |
Instance Method Details
#dump ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dnser/domain.rb', line 37 def dump @builder.origin @name @builder.ttl @ttl_val @records_tmp = @records.dup soa_index = @records_tmp.index {|x| x.is_a?(DNSer::SoaRecord) } @builder.write @records_tmp.delete_at( soa_index ) if soa_index ns = [] @records_tmp = @records_tmp.map do |r| if r.type.to_s.downcase == 'ns' @builder.write r nil else r end end .compact # @records_tmp.sort! {|x, y| x.host <=> y.host } @records_tmp.each {|r| @builder.write r } @builder.sync end |
#ttl(*args) ⇒ Object
32 33 34 35 |
# File 'lib/dnser/domain.rb', line 32 def ttl(*args) @ttl_val = args.first unless args.empty? @ttl_val end |