Class: RactorDNS::ZoneCollection
- Inherits:
-
Object
- Object
- RactorDNS::ZoneCollection
- Defined in:
- lib/ractor_dns/zone_collection.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](k) ⇒ Object
- #freeze ⇒ Object
-
#initialize(obj = {}) ⇒ ZoneCollection
constructor
A new instance of ZoneCollection.
- #inspect ⇒ Object (also: #to_s)
- #search(name) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #to_h ⇒ Object
- #transact(transaction) ⇒ Object
Constructor Details
#initialize(obj = {}) ⇒ ZoneCollection
Returns a new instance of ZoneCollection.
3 4 5 |
# File 'lib/ractor_dns/zone_collection.rb', line 3 def initialize(obj = {}) @obj = obj end |
Class Method Details
.search(obj, name) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/ractor_dns/zone_collection.rb', line 43 def self.search(obj, name) if name.nil? return nil end if name.is_a? RRs::Name name = name.to_a end obj.dig(name.join(".")).presence || ZoneCollection.search(obj, name.drop(1)) end |
Instance Method Details
#[](k) ⇒ Object
53 54 55 56 |
# File 'lib/ractor_dns/zone_collection.rb', line 53 def [](k) @queue.send([:get, k]) @queue.take end |
#freeze ⇒ Object
71 72 73 |
# File 'lib/ractor_dns/zone_collection.rb', line 71 def freeze FrozenZoneCollection.new(to_h) end |
#inspect ⇒ Object Also known as: to_s
79 80 81 82 83 84 85 |
# File 'lib/ractor_dns/zone_collection.rb', line 79 def inspect begin to_h.inspect rescue "Unable to inspect, try starting the server" end end |
#search(name) ⇒ Object
38 39 40 41 |
# File 'lib/ractor_dns/zone_collection.rb', line 38 def search(name) @queue.send([:search, name]) @queue.take end |
#start ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ractor_dns/zone_collection.rb', line 7 def start @queue = Ractor.new(Ractor.make_shareable(@obj.freeze)) do |obj| zones = obj.dup loop do msg, data = Ractor.receive if msg == :transact transaction = data.dup begin transaction.apply(zones) Ractor.yield zones.to_h rescue => e puts e transaction.rollback(zones) raise e end elsif msg == :get Ractor.yield zones[data] elsif msg == :search Ractor.yield ZoneCollection.search(zones, data) elsif msg == :all Ractor.yield zones elsif msg == :stop Ractor.current.close_incoming Ractor.current.close_outgoing break end end end end |
#stop ⇒ Object
75 76 77 |
# File 'lib/ractor_dns/zone_collection.rb', line 75 def stop @queue.send([:stop, nil]) end |
#to_h ⇒ Object
58 59 60 61 |
# File 'lib/ractor_dns/zone_collection.rb', line 58 def to_h @queue.send([:all, nil]) @queue.take end |
#transact(transaction) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/ractor_dns/zone_collection.rb', line 63 def transact(transaction) if !transaction.is_a? RactorDNS::Transaction raise "#{transaction.to_s} is not a transaction" end @queue.send([:transact, Ractor.make_shareable(transaction)]) @queue.take end |