Class: Dslimple::Zone

Inherits:
Object
  • Object
show all
Defined in:
lib/dslimple/zone.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Zone

Returns a new instance of Zone.



8
9
10
11
# File 'lib/dslimple/zone.rb', line 8

def initialize(name)
  @name = name
  @records = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/dslimple/zone.rb', line 5

def name
  @name
end

#recordsObject

Returns the value of attribute records.



6
7
8
# File 'lib/dslimple/zone.rb', line 6

def records
  @records
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/dslimple/zone.rb', line 13

def ==(other)
  other.is_a?(self.class) && hash == other.hash && records.hash == other.records.hash
end

#===(other) ⇒ Object



17
18
19
# File 'lib/dslimple/zone.rb', line 17

def ===(other)
  other.is_a?(self.class) && hash == other.hash
end

#clean_records(ignores) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/dslimple/zone.rb', line 37

def clean_records(ignores)
  ignores = [ignores].flatten.map(&:to_s)

  records.select do |record|
    next false if ignores.include?('system') && record.system_record?
    next false if ignores.include?('child') && record.child_record?
    true
  end
end

#hashObject



21
22
23
# File 'lib/dslimple/zone.rb', line 21

def hash
  [name, records.map(&:hash)].hash
end

#to_dsl(options = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/dslimple/zone.rb', line 29

def to_dsl(options = {})
<<DSL
zone #{name.inspect} do
#{clean_records(options[:ignore]).map { |record| record.to_dsl(options) }.join("\n\n")}
end
DSL
end

#to_sObject



25
26
27
# File 'lib/dslimple/zone.rb', line 25

def to_s
  name
end