mirror of
https://github.com/meineerde/rackstash.git
synced 2025-10-17 14:01:01 +00:00
Allow to clone and dup a ClassRegistry object
This commit is contained in:
parent
76731b1d77
commit
42500162fb
@ -139,5 +139,23 @@ module Rackstash
|
||||
def to_h
|
||||
@registry.dup
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_reader :registry
|
||||
|
||||
private
|
||||
|
||||
def initialize_dup(source)
|
||||
super
|
||||
@registry = source.registry.dup
|
||||
self
|
||||
end
|
||||
|
||||
def initialize_clone(source)
|
||||
super
|
||||
@registry = source.registry.clone
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -126,6 +126,41 @@ RSpec.describe Rackstash::ClassRegistry do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#clone' do
|
||||
it 'clones the registry' do
|
||||
clone = registry.dup
|
||||
expect(clone).to be_instance_of described_class
|
||||
expect(clone.object_type).to eq registry.object_type
|
||||
|
||||
registry[:name] = klass
|
||||
expect(clone).to be_none
|
||||
end
|
||||
|
||||
it 'keeps the frozen state' do
|
||||
expect(registry.freeze).to be_frozen
|
||||
|
||||
clone = registry.clone
|
||||
expect(clone).to be_frozen
|
||||
expect { clone[:name] = klass }.to raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dup' do
|
||||
it 'duplicates the registry' do
|
||||
duplicated = registry.dup
|
||||
expect(duplicated).to be_instance_of described_class
|
||||
expect(duplicated.object_type).to eq registry.object_type
|
||||
|
||||
registry[:name] = klass
|
||||
expect(duplicated).to be_none
|
||||
end
|
||||
|
||||
it 'unfreezes the copy' do
|
||||
expect(registry.freeze).to be_frozen
|
||||
expect(registry.dup).not_to be_frozen
|
||||
end
|
||||
end
|
||||
|
||||
describe '#each' do
|
||||
it 'yield each registered pait' do
|
||||
registry['name'] = klass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user