Module: VagrantDNS::Store::InstanceMethods

Defined in:
lib/vagrant-dns/store.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object

This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.



8
9
10
11
# File 'lib/vagrant-dns/store.rb', line 8

def [](name)
  name = name.source if name.respond_to? :source
  @store[name]
end

#[]=(name, value) ⇒ Object

This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.



14
15
16
17
# File 'lib/vagrant-dns/store.rb', line 14

def []=(name, value)
  name = name.source if name.respond_to? :source
  @store[name] = value
end

#any?Boolean

This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.

Returns:

  • (Boolean)


38
39
40
# File 'lib/vagrant-dns/store.rb', line 38

def any?
  @store.roots.any?
end

#delete(name) ⇒ Object



19
20
21
22
# File 'lib/vagrant-dns/store.rb', line 19

def delete(name)
  name = name.source if name.respond_to? :source
  @store.delete(name)
end

#root?(name) ⇒ Boolean Also known as: key?

This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/vagrant-dns/store.rb', line 25

def root?(name)
  name = name.source if name.respond_to? :source
  @store.root?(name)
end

#rootsObject Also known as: keys

This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.



32
33
34
# File 'lib/vagrant-dns/store.rb', line 32

def roots
  @store.roots.map { |name| Regexp.new(name) }
end

#to_hashObject



42
43
44
45
46
47
48
# File 'lib/vagrant-dns/store.rb', line 42

def to_hash
  @store.transaction(true) do
    @store.roots.each_with_object({}) do |name, a|
      a[Regexp.new(name)] = @store[name]
    end
  end
end