Comments (4)
Sounds like a good example. I won't have time for a bit to do this, but I welcome pull requests! ;)
from aquarium.
I would be happy to generate one if you could give me an outline of how to start. Aspects are much harder than simple monkey patches. You have to keep the original method intact while adding a proxy method around it. I'm still digging into aquarium's internals to see how you did it.
from aquarium.
Sure thing. Thanks for taking an interest. You could start with this
example from the home page, which does tracing:
class ServiceTracer 2 http://aquarium.rubyforge.org/#n2 include
Aquarium::DSL 3 http://aquarium.rubyforge.org/#n3 # jp => the
current "join point" 4 http://aquarium.rubyforge.org/#n4 before
:calls_to => :all_methods, :in_types => /Service$/ do |jp, object,
_args| 5 http://aquarium.rubyforge.org/#n5 names =
"#{jp.target_type.name}##{jp.method_name}" 6
http://aquarium.rubyforge.org/#n6 log "Entering: #{names}: object
= #{object}, args = #{args}" 7 http://aquarium.rubyforge.org/#n7
end 8 http://aquarium.rubyforge.org/#n8 after :calls_to =>
:all_methods, :in_types => /Service$/ do |jp, object, args| 9
http://aquarium.rubyforge.org/#n9 names =
"#{jp.target_type.name}##{jp.method_name}"_10
http://aquarium.rubyforge.org/#n10\ log "Leaving: #{names}:
object = #{object}, args = #{args}" 11
http://aquarium.rubyforge.org/#n11 end12
http://aquarium.rubyforge.org/#n12end
Note that the "names" variable is constructed using the joinpoint
"target_type". This is the type of object being advised. You could compare
this type or even its name with the expected type(s). You only need
"before" advice, unless you also want to check return types. I would throw
an exception for mismatches, but perhaps you'll want to do something else.
If you haven't seen it, the case gem is a nice tool for "pattern matching"
on types and values: https://rubygems.org/gems/case
Finally, if you use this in real code, be sure to prototype the performance
and make sure the overhead isn't excessive. If it is "expensive", consider
just advising entry points to an API, rather than everywhere.
Good luck!
dean
On Thu, Jan 30, 2014 at 4:13 PM, Chad Brewbaker [email protected]:
I would be happy to generate one if you could give me an outline of how to
start. Aspects are much harder than simple monkey patches. You have to keep
the original method intact while adding a proxy method around it. I'm still
digging into aquarium's internals to see how you did it.Reply to this email directly or view it on GitHubhttps://github.com//issues/40#issuecomment-33696449
.
Dean Wampler, Ph.D.
Typesafe
"Functional Programming for Java Developers",
"Programming Scala", and
"Programming Hive" - all from O'Reilly
twitter: @deanwampler, @chicagoscala
http://typesafe.com
http://polyglotprogramming.com
from aquarium.
I just wanted to log type mismatches on assignment operators. Not something you would run in production, just as a testing tool. I'll try out your suggestion.
The approach I had thought out was inserting a proxy into BasicObject that caught the := and :[]= operators, but I got stuck on the details of exactly how to do that.
from aquarium.
Related Issues (20)
- [RubyForge-18458] Add :around_and_return advice? HOT 1
- [RubyForge-19122] Reusable aspects: deferred definition of pointcuts and advising of join points
- [RubyForge-19671] Figure out how to get RDocs generated for methods generated using metaprogramming HOT 1
- [RubyForge-21291] Eliminate most "require File.dirname(__FILE__) + ..." HOT 1
- [RubyForge-22558] Support Ruby 1.9
- [RubyForge-27235] Support RSpec 1.2.8 (latest) and and JRuby 1.3.1 (latest)
- [RubyForge-27236] Upgrade website generation to webgen 5.X HOT 1
- Use Aquarium in a Rails project to display Notifications HOT 1
- Make it easier to use Aquarium from Bundler HOT 2
- Enable setting of default :method_options
- Aquarium::Finders::TypeFinder#empty HOT 3
- Rakefile is out of date HOT 1
- Aquarium is not thread-safe HOT 6
- Aquarium 0.5.1 and Ruby 1.9.3 HOT 3
- uninitialized constant error HOT 2
- Move home page ("docs") and Rubydocs to a better location
- The `String.to_camel_case` patch collides with the patch from another gem HOT 4
- Host documentation an update links for the new ownership
- SortedSet have been removed from Ruby Standard Library failing the specs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aquarium.