CircleCI Code Climate Test Coverage

Okuribito

https://rubygems.org/gems/okuribito

okuribito

Okuribito is a gem to judge whether methods should be sent to the heaven :innocent:.

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::OkuribitoPatch.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::OkuribitoPatch.new(once_detect: true) do |method_name, obj_name, caller_info|
  # do something as you like!
end
okuribito.apply("config/okuribito.yml")

ex: Ruby On Rails

Edit application.rb

class OkuribitoSetting < Rails::Railtie
  config.after_initialize do
    okuribito = Okuribito::OkuribitoPatch.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::OkuribitoPatch.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::OkuribitoPatch.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...

License

The gem is available as open source under the terms of the MIT License. Copyright 2016 Yasuhiro Matsumura.