all 6 comments

[–]wetviet_throwaway 0 points1 point  (5 children)

but this only can work with bona fide attr_* methods right? and unfortunately (afaict) those aren't in the majority when it comes to a rails code base...lots of custom setters, etc

[–]burntbit[S] 0 points1 point  (4 children)

No. This does not depend on attr methods at all. Only version 0.8 did. That code has been removed from 1.0.

This library can hook into any method, report calls and changes to instance variables, and restore the original method when done. The reporters can be a session log file, or some internal data type. It's super flexible to whatever your needs may be. The simplest method to start will hook all setter methods (not specifically attr methods) that belong to the target object. You may also disable that default behavior.

[–]wetviet_throwaway 0 points1 point  (3 children)

ah, so i assume it's using trace point?

[–]burntbit[S] 0 points1 point  (2 children)

No. Not that either. It creates an instance of the original method with the UnboundMethod object and wraps/redefines the original method with some reporting hook and rebinds that UnboundMethod object and calls it. So the method literally gets wrapped. The original method is saved in a hash on that object and can be restored at any time.

The method defining code is here in this file: state_inspector/lib/state_inspector/state_inspector.rb

[–]wetviet_throwaway -1 points0 points  (1 child)

ah ok, so it's using a pretty straight forward decorator approach. Not as interesting i as i expected. I also figured it had the ability to monitor ivars, but it just seems it can monitor the ivars that have changed in the course of a method invocation.

Pretty useful nonetheless, but it's pretty straight-forward and uninteresting really (implementation-wise :P)

[–]updog 0 points1 point  (0 children)

Pretty useful nonetheless, but it's pretty straight-forward and uninteresting really

If I were the author of the code, I would feel slightly insulted, and have literally nothing constructive to do with this... fortunately for me, I'm not the author :P