Okuribito
https://rubygems.org/gems/okuribito
Okuribito is a gem to judge whether methods should be sent to the heaven 😇.
Okuribito monitors the method call with YAML, and exec specified code.
In other words, it can be used in order to extract the uncalled method.
Okuribito was named after a japanese movie.
Installation
Add this line to your application's Gemfile:
gem 'okuribito'
And then execute:
$ bundle
Or install it yourself as:
$ gem install okuribito
Usage
Add config/okuribito.yml
and edit it.
User:
- '#feed'
Micropost:
- '.from_users_followed_by'
Admin::Manage:
- '.add_user'
By writing the following code to start the monitoring of the method.
okuribito = Okuribito::Request.new do |method_name, obj_name, caller_info|
# do something as you like!
end
okuribito.apply("config/okuribito.yml")
You can also give the option.
once_detect
: When it detects a method call, and run only once the code that has been set.
okuribito = Okuribito::Request.new(once_detect: true) do |method_name, obj_name, caller_info|
# do something as you like!
end
okuribito.apply("config/okuribito.yml")
You can also monitor a single method with a string specification.
okuribito = Okuribito::Request.new do |method_name, obj_name, caller_info|
# do something as you like!
end
okuribito.apply_one("TestTarget#deprecated_method")
You can use the following parameters when executing arbitrary code.
- method_name
- obj_name
- caller_info (backtrace)
- class_name
- symbol (
.
or#
) - args
okuribito = Okuribito::Request.new do |method_name, obj_name, caller_info, class_name, symbol, args|
# do something as you like!
end
okuribito.apply_one("TestTarget#deprecated_method_with_args")
ex: Ruby On Rails
Edit application.rb
class OkuribitoSetting < Rails::Railtie
config.after_initialize do
okuribito = Okuribito::Request.new do |method_name, obj_name, caller_info|
# do something as you like!
end
okuribito.apply("config/okuribito.yml")
end
end
The smallest example
require "bundler/setup"
require "okuribito"
class TestTarget
def self.deprecated_self_method
end
def deprecated_method
end
end
okuribito = Okuribito::Request.new do |method_name, obj_name, caller_info|
puts "#{obj_name} #{method_name} #{caller_info[0]}"
end
okuribito.apply("config/okuribito.yml")
TestTarget.deprecated_self_method
TestTarget.new.deprecated_method
Setting file:
TestTarget:
- ".deprecated_self_method"
- "#deprecated_method"
Output:
TestTarget deprecated_self_method example.rb:17:in `<main>'
#<TestTarget:0x007fd1e11ce368> deprecated_method example.rb:18:in `<main>'
Callback examples
Full stacktrace
okuribito = Okuribito::Request.new do |method_name, obj_name, caller_info|
puts "#############################################################"
puts "#{obj_name} #{method_name} #{caller_info[0]}"
puts "#############################################################"
puts caller_info
end
okuribito.apply("config/okuribito.yml")
Other ideas
- Send to Fluentd, TreasureData, Slack...
Compatibility
-
Okuribito::OkuribitoPatch
has backward compatibility, but it is old class! - Later version 0.3.0, you should use
Okuribito::Request
License
The gem is available as open source under the terms of the MIT License. Copyright 2016 Yasuhiro Matsumura.