Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cheap_advice

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheap_advice

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= cheap_advice

Add/remove advice around, before or after methods in Ruby.

== Example

class MyClass def foo 42 end end

class MyOtherClass def bar 43 end end

a = MyClass.new b = MyOtherClass.new

trace_advice = CheapAdvice.new(:around) do | ar, body | ar.advice[:log].puts "#{Time.now.iso8601(6)} #{ar.rcvr.class} #{ar.method} #{ar.rcvr.object_id}" body.call ar.advice[:log].puts "#{Time.now.iso8601(6)} #{ar.rcvr.class} #{ar.method} #{ar.rcvr.object_id} => #{ar.result.inspect}"
end trace_advice[:log] = File.open("trace.log", "a+") trace_advice.advise!(MyClass, :foo) trace_advice.advise!(MyOtherClass, :bar)

a.foo b.bar

trace_advice.disable!

a.foo b.bar

trace.log will contain something like:

2011-01-17T16:33:27.882122-06:00 MyClass foo 69872883178280 2011-01-17T16:33:27.882262-06:00 MyClass foo 69872883178280 => 42 2011-01-17T16:33:27.882319-06:00 MyOtherClass bar 69872883178200 2011-01-17T16:33:27.882367-06:00 MyOtherClass bar 69872883178200 => 43

== Other Features

  • CheapAdvice::Configuration provides a generic mechanism to configure multiple advices on different methods.
  • CheapAdvice::Trace provides an example advice factory for generic method tracing/logging. See examples/ex02.rb.

== Issues

  • Rails-type autoloading can confuse CheapAdvice.

== Contributing to cheap_advice

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2008-2011 Kurt Stephens. See LICENSE.txt for further details.

FAQs

Package last updated on 14 Nov 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc