1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

Rename the abstract adapter base class to BaseAdapter

This avoides the name clashes (and the resulting uncertanty with name
resolution) between the base class and its containing module.
This commit is contained in:
Holger Just 2017-10-21 16:48:59 +02:00
parent d721c1fc72
commit 57119a3266
9 changed files with 32 additions and 32 deletions

View File

@ -41,12 +41,12 @@ module Rackstash
# @param matchers [Array<String, Symbol, #===>] a list of specifications
# for log devices the `adapter_class` can forward logs to.
# @raise [TypeError] if the passed adapter_class is not a class
# inheriting from {Adapter::Adapter}
# inheriting from {BaseAdapter}
# @return [Class] the `adapter_class`
def register(adapter_class, *matchers)
unless adapter_class.is_a?(Class) && adapter_class < Rackstash::Adapter::Adapter
unless adapter_class.is_a?(Class) && adapter_class < BaseAdapter
raise TypeError, 'adapter_class must be a class and inherit from ' \
'Rackstash::Adapter::Adapter'
'Rackstash::Adapter::BaseAdapter'
end
matchers.flatten.each do |matcher|
@ -85,14 +85,14 @@ module Rackstash
#
# if no suitable adapter can be found, we raise an `ArgumentError`.
#
# @param device [Adapter::Adapter, Object] a log device which should be
# wrapped in an {Adapter}. If it is already an adapter, the `device` is
# returned unchanged.
# @param device [BaseAdapter, Object] a log device which should be
# wrapped in an adapter object. If it is already an adapter, the
# `device` is returned unchanged.
# @raise [ArgumentError] if no suitable adapter could be found for the
# provided `device`
# @return [Adapter::Adapter] the resolved adapter instance
def [](device)
return device if device.is_a?(Rackstash::Adapter::Adapter)
return device if device.is_a?(BaseAdapter)
adapter = adapter_by_uri(device)
adapter ||= adapter_by_type(device)

View File

@ -20,7 +20,7 @@ module Rackstash
#
# @abstract Subclasses need to override at least {#write_single} to
# implement a concrete log adapter.
class Adapter
class BaseAdapter
# Register the current class as an adapter for the provided matchers.
#
# This is a convenience method intended to be used by sub-classes of this

View File

@ -5,7 +5,7 @@
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'rackstash/adapter/adapter'
require 'rackstash/adapter/base_adapter'
require 'rackstash/encoder/hash'
module Rackstash
@ -27,7 +27,7 @@ module Rackstash
# Rackstash::Adapter::Callable.new do |log|
# # handle the log as required
# end
class Callable < Adapter
class Callable < BaseAdapter
register_for ::Proc, :call
# Create a new Callable adapter by wrapping a proc. You can pass the proc

View File

@ -9,7 +9,7 @@ require 'fileutils'
require 'pathname'
require 'thread'
require 'rackstash/adapter/adapter'
require 'rackstash/adapter/base_adapter'
module Rackstash
module Adapter
@ -56,7 +56,7 @@ module Rackstash
# Since the {File} adapter automatically reopens the logfile after the
# file was moved, you don't need to create the new file there nor should you
# use the (potentially destructive) `copytruncate` option of logrotate.
class File < Adapter
class File < BaseAdapter
register_for ::String, ::Pathname
# @return [String] the absolute path to the log file

View File

@ -7,7 +7,7 @@
require 'thread'
require 'rackstash/adapter/adapter'
require 'rackstash/adapter/base_adapter'
module Rackstash
module Adapter
@ -31,7 +31,7 @@ module Rackstash
# different adapter to ensure consistent logs. Suitable adapters for this
# use-case include {Rackstash::Adapter::File} or
# {Rackstash::Adapter::TCP}.
class IO < Adapter
class IO < BaseAdapter
# This module is by default included into all objects passed to
# {Adapter::IO#initialize}. It allows to synchronize all write accesses
# against this object, even when writing to the same object from multiple

View File

@ -7,7 +7,7 @@
require 'logger'
require 'rackstash/adapter/adapter'
require 'rackstash/adapter/base_adapter'
module Rackstash
module Adapter
@ -34,7 +34,7 @@ module Rackstash
# `STDERR`), you should use the {File} encoder respectively the {IO} encoder
# instead which usally provide stronger consistency guarantees and are
# faster.
class Logger < Adapter
class Logger < BaseAdapter
register_for ::Logger, 'Syslog::Logger'
# @param logger [#add] A base logger to send log lines to. We only expect

View File

@ -5,7 +5,7 @@
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'rackstash/adapter/adapter'
require 'rackstash/adapter/base_adapter'
require 'rackstash/encoder/raw'
module Rackstash
@ -14,7 +14,7 @@ module Rackstash
#
# It is probably not very useful for production use but can be used to test
# the {Flow} pipeline.
class Null < Adapter
class Null < BaseAdapter
register_for NilClass
# Create a new black hole adapter. Any logs written to it will be

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/adapter/adapter'
require 'rackstash/adapter/base_adapter'
describe Rackstash::Adapter::Adapter do
describe Rackstash::Adapter::BaseAdapter do
let(:adapter) { described_class.new }
describe '#initialize' do

View File

@ -24,7 +24,7 @@ describe Rackstash::Adapter do
end
let(:adapter) {
Class.new(Rackstash::Adapter::Adapter) do
Class.new(Rackstash::Adapter::BaseAdapter) do
def self.from_uri(*args)
new(*args)
end
@ -115,7 +115,7 @@ describe Rackstash::Adapter do
expect(device_class).to receive(:===).with(device).and_call_original
expect(adapter).to receive(:new).with(device).and_call_original
expect(described_class[device]).to be_an Rackstash::Adapter::Adapter
expect(described_class[device]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'creates an adapter if any parent class was found' do
@ -123,7 +123,7 @@ describe Rackstash::Adapter do
expect(device_class).to receive(:===).with(inherited_device).and_call_original
expect(adapter).to receive(:new).with(inherited_device).and_call_original
expect(described_class[inherited_device]).to be_an Rackstash::Adapter::Adapter
expect(described_class[inherited_device]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'raises if no class was found' do
@ -149,14 +149,14 @@ describe Rackstash::Adapter do
device = SpecDevice.new
expect(adapter).to receive(:new).with(device).and_call_original
expect(described_class[device]).to be_an Rackstash::Adapter::Adapter
expect(described_class[device]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'creates an adapter if any parent class was found' do
inherited_device = InheritedSpecDevice.new
expect(adapter).to receive(:new).with(inherited_device).and_call_original
expect(described_class[inherited_device]).to be_an Rackstash::Adapter::Adapter
expect(described_class[inherited_device]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'raises if no class was found' do
@ -174,7 +174,7 @@ describe Rackstash::Adapter do
device = Struct.new(:foo).new('foo')
expect(adapter).to receive(:new).with(device).and_call_original
expect(described_class[device]).to be_an Rackstash::Adapter::Adapter
expect(described_class[device]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'raises if it does not respond to the registered method' do
@ -194,7 +194,7 @@ describe Rackstash::Adapter do
expect(checker).to receive(:===).with(device).and_call_original
expect(adapter).to receive(:new).with(device).and_call_original
expect(described_class[device]).to be_an Rackstash::Adapter::Adapter
expect(described_class[device]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'does not create an adapter if the proc returns false' do
@ -215,11 +215,11 @@ describe Rackstash::Adapter do
it 'creates an adapter from the scheme' do
raw_uri = 'dummy://example.com'
expect(adapter).to receive(:from_uri).with(URI(raw_uri)).and_call_original
expect(described_class[raw_uri]).to be_an Rackstash::Adapter::Adapter
expect(described_class[raw_uri]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'calls adapter.new if adapter.from_uri is not available' do
plain_adapter = Class.new(Rackstash::Adapter::Adapter)
plain_adapter = Class.new(Rackstash::Adapter::BaseAdapter)
described_class.register plain_adapter, 'dummy'
raw_uri = 'dummy://example.com'
@ -231,7 +231,7 @@ describe Rackstash::Adapter do
it 'creates an adapter from a URI' do
uri = URI('dummy://example.com')
expect(adapter).to receive(:from_uri).with(uri).and_call_original
expect(described_class[uri]).to be_an Rackstash::Adapter::Adapter
expect(described_class[uri]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'raises if no scheme was found' do
@ -254,7 +254,7 @@ describe Rackstash::Adapter do
expect(adapter).to_not receive(:from_uri)
# from the fallback
expect(adapter).to receive(:new).with(invalid_uri).and_call_original
expect(described_class[invalid_uri]).to be_an Rackstash::Adapter::Adapter
expect(described_class[invalid_uri]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'falls though if no scheme was found' do
@ -262,7 +262,7 @@ describe Rackstash::Adapter do
expect(adapter).to_not receive(:from_uri)
expect(adapter).to receive(:new).with(unknown_uri).and_call_original
expect(described_class[unknown_uri]).to be_an Rackstash::Adapter::Adapter
expect(described_class[unknown_uri]).to be_an Rackstash::Adapter::BaseAdapter
end
end
end