diff --git a/Gemfile b/Gemfile index b733b8a..2168bc7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash.rb b/lib/rackstash.rb index 6710488..60dae1e 100644 --- a/lib/rackstash.rb +++ b/lib/rackstash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/adapters.rb b/lib/rackstash/adapters.rb index f8d5730..54ac7fd 100644 --- a/lib/rackstash/adapters.rb +++ b/lib/rackstash/adapters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/adapters/adapter.rb b/lib/rackstash/adapters/adapter.rb index ff03c25..066e914 100644 --- a/lib/rackstash/adapters/adapter.rb +++ b/lib/rackstash/adapters/adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms @@ -97,10 +99,11 @@ module Rackstash # that ends in a newline character by mutating the object is required. # # @param line [#to_s] a log line - # @return [String] a string with a trailing newline character (`"\n"`) + # @return [String] `line` with a trailing newline character (`"\n"`) + # appended if necessary def normalize_line(line) line = line.to_s - line << "\n".freeze unless line.end_with?("\n".freeze) + line = "#{line}\n" unless line.end_with?("\n".freeze) line end end diff --git a/lib/rackstash/adapters/callable.rb b/lib/rackstash/adapters/callable.rb index 9a129ec..0f95d36 100644 --- a/lib/rackstash/adapters/callable.rb +++ b/lib/rackstash/adapters/callable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/adapters/file.rb b/lib/rackstash/adapters/file.rb index ef8bb53..eae480a 100644 --- a/lib/rackstash/adapters/file.rb +++ b/lib/rackstash/adapters/file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/adapters/io.rb b/lib/rackstash/adapters/io.rb index 61a202d..7fd32b9 100644 --- a/lib/rackstash/adapters/io.rb +++ b/lib/rackstash/adapters/io.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/buffer.rb b/lib/rackstash/buffer.rb index 1e978fd..518ce7d 100644 --- a/lib/rackstash/buffer.rb +++ b/lib/rackstash/buffer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/buffer_stack.rb b/lib/rackstash/buffer_stack.rb index 46381f2..40eda59 100644 --- a/lib/rackstash/buffer_stack.rb +++ b/lib/rackstash/buffer_stack.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/encoders.rb b/lib/rackstash/encoders.rb index 056824b..816528a 100644 --- a/lib/rackstash/encoders.rb +++ b/lib/rackstash/encoders.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/encoders/json.rb b/lib/rackstash/encoders/json.rb index 25b475f..b6442c2 100644 --- a/lib/rackstash/encoders/json.rb +++ b/lib/rackstash/encoders/json.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms @@ -21,7 +23,7 @@ module Rackstash # @param event [Hash] a log event as produced by the {Flow} # @return [String] the event as a single-line JSON string def encode(event) - event[FIELD_MESSAGE].strip! + event[FIELD_MESSAGE] = event[FIELD_MESSAGE].strip ::JSON.dump(event) end end diff --git a/lib/rackstash/encoders/message.rb b/lib/rackstash/encoders/message.rb index f7615c7..5833dae 100644 --- a/lib/rackstash/encoders/message.rb +++ b/lib/rackstash/encoders/message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/encoders/raw.rb b/lib/rackstash/encoders/raw.rb index 82fd267..8608901 100644 --- a/lib/rackstash/encoders/raw.rb +++ b/lib/rackstash/encoders/raw.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/fields.rb b/lib/rackstash/fields.rb index 8c9d35a..6bfb7a6 100644 --- a/lib/rackstash/fields.rb +++ b/lib/rackstash/fields.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/fields/abstract_collection.rb b/lib/rackstash/fields/abstract_collection.rb index cd4d9d8..7a8068e 100644 --- a/lib/rackstash/fields/abstract_collection.rb +++ b/lib/rackstash/fields/abstract_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms @@ -156,7 +158,7 @@ module Rackstash return utf8_encode(value) when Exception exception = "#{value.message} (#{value.class})" - exception << "\n" << value.backtrace.join("\n") if value.backtrace + exception = [exception, *value.backtrace].join("\n") if value.backtrace return utf8_encode(exception) when ::Proc return normalize(value, scope: scope, wrap: wrap) diff --git a/lib/rackstash/fields/array.rb b/lib/rackstash/fields/array.rb index 3260904..d1955c5 100644 --- a/lib/rackstash/fields/array.rb +++ b/lib/rackstash/fields/array.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/fields/hash.rb b/lib/rackstash/fields/hash.rb index 9b14060..de469e1 100644 --- a/lib/rackstash/fields/hash.rb +++ b/lib/rackstash/fields/hash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/fields/tags.rb b/lib/rackstash/fields/tags.rb index bd476e6..3b76623 100644 --- a/lib/rackstash/fields/tags.rb +++ b/lib/rackstash/fields/tags.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/flow.rb b/lib/rackstash/flow.rb index 783a311..ca8281c 100644 --- a/lib/rackstash/flow.rb +++ b/lib/rackstash/flow.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/flows.rb b/lib/rackstash/flows.rb index f3c95a7..5dc130e 100644 --- a/lib/rackstash/flows.rb +++ b/lib/rackstash/flows.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/formatter.rb b/lib/rackstash/formatter.rb index b51378b..0fb8878 100644 --- a/lib/rackstash/formatter.rb +++ b/lib/rackstash/formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/logger.rb b/lib/rackstash/logger.rb index ab62675..6b6d424 100644 --- a/lib/rackstash/logger.rb +++ b/lib/rackstash/logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/message.rb b/lib/rackstash/message.rb index 8059cf4..0c5de1e 100644 --- a/lib/rackstash/message.rb +++ b/lib/rackstash/message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/sink.rb b/lib/rackstash/sink.rb index 66ff9cc..2180a18 100644 --- a/lib/rackstash/sink.rb +++ b/lib/rackstash/sink.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/lib/rackstash/version.rb b/lib/rackstash/version.rb index 66a9251..b4387e3 100644 --- a/lib/rackstash/version.rb +++ b/lib/rackstash/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/rackstash.gemspec b/rackstash.gemspec index 91558ca..3fd1a69 100644 --- a/rackstash.gemspec +++ b/rackstash.gemspec @@ -1,4 +1,5 @@ -# coding: utf-8 +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/adapters/adapter_spec.rb b/spec/rackstash/adapters/adapter_spec.rb index 62547db..710d6e3 100644 --- a/spec/rackstash/adapters/adapter_spec.rb +++ b/spec/rackstash/adapters/adapter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/adapters/callable_spec.rb b/spec/rackstash/adapters/callable_spec.rb index d453be6..a2d0f89 100644 --- a/spec/rackstash/adapters/callable_spec.rb +++ b/spec/rackstash/adapters/callable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/adapters/file_spec.rb b/spec/rackstash/adapters/file_spec.rb index feffdc5..0871c67 100644 --- a/spec/rackstash/adapters/file_spec.rb +++ b/spec/rackstash/adapters/file_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/adapters/io_spec.rb b/spec/rackstash/adapters/io_spec.rb index 6ac501d..ba663c7 100644 --- a/spec/rackstash/adapters/io_spec.rb +++ b/spec/rackstash/adapters/io_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/adapters_spec.rb b/spec/rackstash/adapters_spec.rb index 1594308..bab9cf4 100644 --- a/spec/rackstash/adapters_spec.rb +++ b/spec/rackstash/adapters_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/buffer_spec.rb b/spec/rackstash/buffer_spec.rb index 6994f23..ff7e2ff 100644 --- a/spec/rackstash/buffer_spec.rb +++ b/spec/rackstash/buffer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/buffer_stack_spec.rb b/spec/rackstash/buffer_stack_spec.rb index d055fc6..59b544a 100644 --- a/spec/rackstash/buffer_stack_spec.rb +++ b/spec/rackstash/buffer_stack_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/encoders/json_spec.rb b/spec/rackstash/encoders/json_spec.rb index 67433e1..bc87943 100644 --- a/spec/rackstash/encoders/json_spec.rb +++ b/spec/rackstash/encoders/json_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/encoders/message_spec.rb b/spec/rackstash/encoders/message_spec.rb index d28a75f..c1a65b6 100644 --- a/spec/rackstash/encoders/message_spec.rb +++ b/spec/rackstash/encoders/message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/encoders/raw_spec.rb b/spec/rackstash/encoders/raw_spec.rb index abdb788..6ded912 100644 --- a/spec/rackstash/encoders/raw_spec.rb +++ b/spec/rackstash/encoders/raw_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/fields/abstract_collection_spec.rb b/spec/rackstash/fields/abstract_collection_spec.rb index 1606202..c79c0f7 100644 --- a/spec/rackstash/fields/abstract_collection_spec.rb +++ b/spec/rackstash/fields/abstract_collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms @@ -63,7 +65,7 @@ describe Rackstash::Fields::AbstractCollection do describe '#clone' do it 'clones the raw value' do - raw = 'hello' + raw = [] collection.send(:raw=, raw) expect(collection.send(:raw)).to equal raw @@ -71,14 +73,14 @@ describe Rackstash::Fields::AbstractCollection do cloned = collection.clone expect(cloned).not_to equal collection - expect(cloned.send(:raw)).to eql 'hello' + expect(cloned.send(:raw)).to eql raw expect(cloned.send(:raw)).not_to equal raw end end describe '#dup' do it 'dups the raw value' do - raw = 'hello' + raw = [] collection.send(:raw=, raw) expect(collection.send(:raw)).to equal raw @@ -86,7 +88,7 @@ describe Rackstash::Fields::AbstractCollection do duped = collection.dup expect(duped).not_to equal collection - expect(duped.send(:raw)).to eql 'hello' + expect(duped.send(:raw)).to eql raw expect(duped.send(:raw)).not_to equal raw end end diff --git a/spec/rackstash/fields/array_spec.rb b/spec/rackstash/fields/array_spec.rb index 41454ab..0833082 100644 --- a/spec/rackstash/fields/array_spec.rb +++ b/spec/rackstash/fields/array_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/fields/hash_spec.rb b/spec/rackstash/fields/hash_spec.rb index 4547008..c1660f4 100644 --- a/spec/rackstash/fields/hash_spec.rb +++ b/spec/rackstash/fields/hash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/fields/tags_spec.rb b/spec/rackstash/fields/tags_spec.rb index c98c205..93e9d58 100644 --- a/spec/rackstash/fields/tags_spec.rb +++ b/spec/rackstash/fields/tags_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/flows_spec.rb b/spec/rackstash/flows_spec.rb index ad4fecf..297eba7 100644 --- a/spec/rackstash/flows_spec.rb +++ b/spec/rackstash/flows_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/formatter_spec.rb b/spec/rackstash/formatter_spec.rb index ea7e0bf..cc0a0ac 100644 --- a/spec/rackstash/formatter_spec.rb +++ b/spec/rackstash/formatter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/logger_spec.rb b/spec/rackstash/logger_spec.rb index 2b9bcda..3b9153f 100644 --- a/spec/rackstash/logger_spec.rb +++ b/spec/rackstash/logger_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/message_spec.rb b/spec/rackstash/message_spec.rb index 03b9e2c..bed3712 100644 --- a/spec/rackstash/message_spec.rb +++ b/spec/rackstash/message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms @@ -108,8 +110,8 @@ describe Rackstash::Message do end describe '#progname' do - it 'dups the progname' do - progname = 'a message' + it 'dup-freezes a mutable progname' do + progname = String.new('a message') message = Rackstash::Message.new('', progname: progname) expect(message.progname).to eql progname diff --git a/spec/rackstash/sink_spec.rb b/spec/rackstash/sink_spec.rb index 1ea79c9..0666562 100644 --- a/spec/rackstash/sink_spec.rb +++ b/spec/rackstash/sink_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash/version_spec.rb b/spec/rackstash/version_spec.rb index 2917640..1a64c4c 100644 --- a/spec/rackstash/version_spec.rb +++ b/spec/rackstash/version_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/rackstash_spec.rb b/spec/rackstash_spec.rb index e02bce3..7da0266 100644 --- a/spec/rackstash_spec.rb +++ b/spec/rackstash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4e4c291..57e0df9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright 2017 Holger Just # # This software may be modified and distributed under the terms