From ba61940a95a165784aa6e7c749d196d4f80791e2 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Sat, 15 Jul 2017 14:28:29 +0200 Subject: [PATCH] Improve code formatting --- lib/rackstash/adapters.rb | 2 +- lib/rackstash/fields/abstract_collection.rb | 6 +++--- lib/rackstash/fields/array.rb | 2 +- lib/rackstash/fields/hash.rb | 2 +- spec/rackstash/adapters/callable_spec.rb | 2 +- spec/rackstash/fields/hash_spec.rb | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/rackstash/adapters.rb b/lib/rackstash/adapters.rb index 3d13978..f8d5730 100644 --- a/lib/rackstash/adapters.rb +++ b/lib/rackstash/adapters.rb @@ -43,7 +43,7 @@ module Rackstash # @return [Class] the `adapter_class` def register(adapter_class, *matchers) unless adapter_class.is_a?(Class) && adapter_class < Adapters::Adapter - raise TypeError, 'adapter_class must be a class and inherit from ' + + raise TypeError, 'adapter_class must be a class and inherit from ' \ 'Rackstash::Adapters::Adapter' end diff --git a/lib/rackstash/fields/abstract_collection.rb b/lib/rackstash/fields/abstract_collection.rb index d616713..cd4d9d8 100644 --- a/lib/rackstash/fields/abstract_collection.rb +++ b/lib/rackstash/fields/abstract_collection.rb @@ -69,13 +69,13 @@ module Rackstash def initialize_dup(source) super - self.raw = source.raw == nil ? nil : source.raw.dup + self.raw = source.raw.nil? ? nil : source.raw.dup self end def initialize_clone(source) super - self.raw = source.raw == nil ? nil : source.raw.clone + self.raw = source.raw.nil? ? nil : source.raw.clone self end @@ -103,7 +103,7 @@ module Rackstash def resolve_value(value, scope: nil) return value unless value.is_a?(Proc) - scope == nil ? value.call : scope.instance_exec(&value) + scope.nil? ? value.call : scope.instance_exec(&value) rescue value.inspect end diff --git a/lib/rackstash/fields/array.rb b/lib/rackstash/fields/array.rb index a52e3b4..3260904 100644 --- a/lib/rackstash/fields/array.rb +++ b/lib/rackstash/fields/array.rb @@ -294,7 +294,7 @@ module Rackstash # @return [self] def unshift(*values, scope: nil) values.map! { |value| normalize(value, scope: scope) } - @raw.unshift *values + @raw.unshift(*values) self end alias prepend unshift diff --git a/lib/rackstash/fields/hash.rb b/lib/rackstash/fields/hash.rb index 58a23e5..9b14060 100644 --- a/lib/rackstash/fields/hash.rb +++ b/lib/rackstash/fields/hash.rb @@ -464,7 +464,7 @@ module Rackstash key = utf8_encode(key) return if forbidden_key?(key) - return unless @raw[key] == nil + return unless @raw[key].nil? @raw[key] = normalize(yield(key)) end diff --git a/spec/rackstash/adapters/callable_spec.rb b/spec/rackstash/adapters/callable_spec.rb index 9c0c81b..d453be6 100644 --- a/spec/rackstash/adapters/callable_spec.rb +++ b/spec/rackstash/adapters/callable_spec.rb @@ -13,7 +13,7 @@ describe Rackstash::Adapters::Callable do describe '#initialize' do it 'accepts a callable' do - expect { Rackstash::Adapters::Callable.new(->{}) }.not_to raise_error + expect { Rackstash::Adapters::Callable.new(-> {}) }.not_to raise_error expect { Rackstash::Adapters::Callable.new(proc {}) }.not_to raise_error expect { Rackstash::Adapters::Callable.new(Struct.new(:call).new) }.not_to raise_error diff --git a/spec/rackstash/fields/hash_spec.rb b/spec/rackstash/fields/hash_spec.rb index 772b095..4547008 100644 --- a/spec/rackstash/fields/hash_spec.rb +++ b/spec/rackstash/fields/hash_spec.rb @@ -354,7 +354,7 @@ describe Rackstash::Fields::Hash do it 'resolves conflicting values with the passed block' do hash['key'] = 'value' - hash.deep_merge!('key' => 'new') { |key, old_val, new_val| [old_val, new_val] } + hash.deep_merge!('key' => 'new') { |_key, old_val, new_val| [old_val, new_val] } expect(hash['key'].as_json).to eql ['value', 'new'] end @@ -363,7 +363,7 @@ describe Rackstash::Fields::Hash do hash['key'] = { 'deep' => 'value' } hash.deep_merge!( 'key' => { 'deep' => 'stuff', 'new' => 'things' } - ) { |key, old_val, new_val| old_val + new_val } + ) { |_key, old_val, new_val| old_val + new_val } expect(hash['key'].as_json).to eql 'deep' => 'valuestuff', 'new' => 'things' end @@ -372,14 +372,14 @@ describe Rackstash::Fields::Hash do hash['key'] = { 'deep' => 'value', 'array' => ['v1'] } hash.deep_merge!( 'key' => { 'deep' => 'stuff', 'array' => ['v2'] } - ) { |key, old_val, new_val| old_val + new_val } + ) { |_key, old_val, new_val| old_val + new_val } expect(hash['key'].as_json).to eql 'deep' => 'valuestuff', 'array' => ['v1', 'v2'] end it 'uses the scope to resolve values returned by the block' do hash['key'] = 'value' - hash.deep_merge!({'key' => 'new'}, scope: 123) { |_key, _old, _new| -> { self } } + hash.deep_merge!({ 'key' => 'new' }, scope: 123) { |_key, _old, _new| -> { self } } expect(hash['key']).to eql 123 end