Class: VagrantDNS::Registry
- Inherits:
-
Object
- Object
- VagrantDNS::Registry
- Extended by:
- Forwardable
- Defined in:
- lib/vagrant-dns/registry.rb
Overview
This is the dns pattern registry (aka “config”) It basically delegates everything to a YAML::Store but handles the conversion of Regexp dns-patterns into YAML string keys and reverse.
Instance Method Summary collapse
-
#[](name) ⇒ Object
This method is only valid in a #transaction and it cannot be read-only.
-
#[]=(name, value) ⇒ Object
This method is only valid in a #transaction and it cannot be read-only.
-
#any? ⇒ Boolean
This method is only valid in a #transaction and it cannot be read-only.
- #delete(name) ⇒ Object
-
#initialize(tmp_path) ⇒ Registry
constructor
A new instance of Registry.
-
#root?(name) ⇒ Boolean
(also: #key?)
This method is only valid in a #transaction and it cannot be read-only.
-
#roots ⇒ Object
(also: #keys)
This method is only valid in a #transaction and it cannot be read-only.
- #to_hash ⇒ Object
Constructor Details
#initialize(tmp_path) ⇒ Registry
Returns a new instance of Registry.
11 12 13 |
# File 'lib/vagrant-dns/registry.rb', line 11 def initialize(tmp_path) @store = YAML::Store.new(File.join(tmp_path, "config"), true) end |
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.
18 19 20 21 |
# File 'lib/vagrant-dns/registry.rb', line 18 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.
24 25 26 27 |
# File 'lib/vagrant-dns/registry.rb', line 24 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.
48 49 50 |
# File 'lib/vagrant-dns/registry.rb', line 48 def any? @store.roots.any? end |
#delete(name) ⇒ Object
29 30 31 32 |
# File 'lib/vagrant-dns/registry.rb', line 29 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.
35 36 37 38 |
# File 'lib/vagrant-dns/registry.rb', line 35 def root?(name) name = name.source if name.respond_to? :source @store.root?(name) end |
#roots ⇒ Object 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.
42 43 44 |
# File 'lib/vagrant-dns/registry.rb', line 42 def roots @store.roots.map { |name| Regexp.new(name) } end |
#to_hash ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/vagrant-dns/registry.rb', line 52 def to_hash @store.transaction(true) do @store.roots.each_with_object({}) do |name, a| a[Regexp.new(name)] = @store[name] end end end |