mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-01 01:37:12 +00:00
Allow to freeze and dup Rackstash::Flows collections
This commit is contained in:
parent
e62af8b1cf
commit
fa73e63a3e
@ -103,6 +103,16 @@ module Rackstash
|
||||
end
|
||||
end
|
||||
|
||||
# Prevents further modifications to the flows list. A `RuntimeError` will be
|
||||
# raised if you attempt to add, delete, or overwrite flows in the list.
|
||||
# There is no way to unfreeze a frozen object.
|
||||
#
|
||||
# @return [self]
|
||||
def freeze
|
||||
@flows.freeze
|
||||
super
|
||||
end
|
||||
|
||||
# @return [String] a string representation of `self`
|
||||
def inspect
|
||||
id_str = Object.instance_method(:to_s).bind(self).call[2..-2]
|
||||
@ -192,8 +202,17 @@ module Rackstash
|
||||
@flows.to_s
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_reader :flows
|
||||
|
||||
private
|
||||
|
||||
def initialize_copy(other)
|
||||
@flows = other.flows.dup
|
||||
super
|
||||
end
|
||||
|
||||
# Create a deep duplicate of an event hash. It is assumed that the input
|
||||
# event follows the normalized structure as generated by
|
||||
# {Fields::Hash#to_h}.
|
||||
|
||||
@ -122,6 +122,41 @@ describe Rackstash::Flows do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dup' do
|
||||
it 'dups the flows' do
|
||||
flows << a_flow
|
||||
copied = flows.dup
|
||||
|
||||
expect(copied).to be_instance_of described_class
|
||||
expect(copied.length).to eql 1
|
||||
expect(copied).to_not equal flows
|
||||
end
|
||||
|
||||
it 'separates the flows' do
|
||||
flows << a_flow
|
||||
|
||||
copied = flows.dup
|
||||
copied << a_flow
|
||||
|
||||
expect(copied.first).to equal flows.first
|
||||
|
||||
expect(flows.length).to eql 1
|
||||
expect(copied.length).to eql 2
|
||||
end
|
||||
end
|
||||
|
||||
describe '#freeze' do
|
||||
it 'freezes the object' do
|
||||
expect(flows.freeze).to equal flows
|
||||
expect(flows).to be_frozen
|
||||
end
|
||||
|
||||
it 'denies all further changes' do
|
||||
flows.freeze
|
||||
expect { flows << a_flow }.to raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reopen' do
|
||||
it 'calls reopen on all flows' do
|
||||
[a_flow, a_flow].each do |flow|
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user