Giter Site home page Giter Site logo

Comments (4)

deanwampler avatar deanwampler commented on May 25, 2024

Sounds like a good example. I won't have time for a bit to do this, but I welcome pull requests! ;)

from aquarium.

chadbrewbaker avatar chadbrewbaker commented on May 25, 2024

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.

deanwampler avatar deanwampler commented on May 25, 2024

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.

chadbrewbaker avatar chadbrewbaker commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.