mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-06 00:53:22 +00:00
Improve code formatting
This commit is contained in:
parent
9f2a330a6c
commit
ba61940a95
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user