Module: Adalog::StubLoggingAdapter
- Defined in:
- lib/adalog/stub_logging_adapter.rb
Defined Under Namespace
Classes: Base
Class Method Summary collapse
-
.new(service_name, repo, **stub_methods) ⇒ Object
A factory to make new classes which implement the MockLogging.
-
.stub_method(message, value) ⇒ Object
An isolated lambda to serve as the method body for stubs, both in the ::new method and in the Base#initialize method.
Class Method Details
.new(service_name, repo, **stub_methods) ⇒ Object
A factory to make new classes which implement the MockLogging
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/adalog/stub_logging_adapter.rb', line 6 def self.new(service_name, repo, **stub_methods) new_logger_class = Class.new(self::Base) new_logger_class.instance_variable_set(:@service_name, service_name) new_logger_class.instance_variable_set(:@repo, repo) stub_methods.each do |, value| new_logger_class.instance_exec do define_method(, &StubLoggingAdapter.stub_method(, value)) end end new_logger_class end |
.stub_method(message, value) ⇒ Object
An isolated lambda to serve as the method body for stubs, both in the ::new method and in the Base#initialize method. Avoids repeating already clunky-looking logic.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/adalog/stub_logging_adapter.rb', line 24 def self.stub_method(, value) ->(*args, &block) { repo.insert( title: service_name, message: "'#{}', which has been stubbed with '#{value}'.", details: args) block.call unless nil == block value } end |