Class: MethodLogger::Mixin
- Inherits:
-
Module
- Object
- Module
- MethodLogger::Mixin
- Defined in:
- lib/method_logger.rb
Instance Method Summary collapse
- #included(base_class) ⇒ Object
-
#initialize(options = {}) ⇒ Mixin
constructor
A new instance of Mixin.
Constructor Details
#initialize(options = {}) ⇒ Mixin
Returns a new instance of Mixin.
6 7 8 9 |
# File 'lib/method_logger.rb', line 6 def initialize( = {}) @_options = .merge() @_methods = [:methods] end |
Instance Method Details
#included(base_class) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/method_logger.rb', line 11 def included(base_class) = @_options methods = @_methods || base_class.instance_methods([:include_inherited]) methods -= Object.methods if [:include_inherited] methods += base_class.private_instance_methods(false) methods -= [:ignored_methods] formatter = .delete(:formatter) || default_formatter logger = [:logger] || default_logger() base_class.class_eval do methods.each do |method_name| method = instance_method(method_name) define_method(method_name) do |*args, &block| return_value = method.bind(self).call(*args, &block) text = formatter.call(base_class, method_name, args.inspect, return_value.inspect) puts(text) if [:log_to_stdout] logger.info(text) if [:log_to_file] return_value end end end end |