Class: DNSCheck::DB

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/dns-check/db.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDB

Returns a new instance of DB.



14
15
16
17
18
19
# File 'lib/dns-check/db.rb', line 14

def initialize
  super
  @Records = Hash.new { |hash, key|
    hash[key] = []
  }
end

Class Method Details

.[](*args) ⇒ Object



21
22
23
24
25
# File 'lib/dns-check/db.rb', line 21

def self.[](*args)
  db = new
  db.instance_variable_set(:@Records, Hash[*args])
  db
end

Instance Method Details

#[](key) ⇒ Object



27
28
29
# File 'lib/dns-check/db.rb', line 27

def [](key)
  @Records[key]
end

#add(k, v) ⇒ Object Also known as: []=



35
36
37
38
39
# File 'lib/dns-check/db.rb', line 35

def add(k, v)
  update(k) do |hash|
    hash << v
  end
end

#dump_allObject

Can’t marshal hash with default proc



43
44
45
46
47
48
# File 'lib/dns-check/db.rb', line 43

def dump_all
  return @Records unless @Records.default_proc
  records = @Records.clone
  records.default = nil
  records
end

#has_key?(k) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/dns-check/db.rb', line 58

def has_key? k
  @Records[k] ? true : false
end

#keysObject



50
51
52
# File 'lib/dns-check/db.rb', line 50

def keys
  @Records.keys
end

#rand_keysObject



62
63
64
# File 'lib/dns-check/db.rb', line 62

def rand_keys
  self.keys.sort_by{rand}
end

#update(k) ⇒ Object



31
32
33
# File 'lib/dns-check/db.rb', line 31

def update k
  @Records[k] = yield(@Records[k])
end

#valuesObject



54
55
56
# File 'lib/dns-check/db.rb', line 54

def values
  @Records.values
end