Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Sinatra app to explore Ruby code in Maglev

tree: ba7d9b771a

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.rdoc

WebTools Example

The WebTools Sinatra application running in MagLev allows you to explore a MagLev Ruby application's Classes, Modules, Methods, Constants, and Ancestors in a web browser.

It will also allow you to explore GemStone/S Smalltalk code, and to examine detailed statistics about all processes connected to GemStone/S.

Setup

  1. Download and install MagLev using instructions at github.com/MagLev/maglev/blob/master/README.rdoc

  2. Start the MagLev server

    $ cd $MAGLEV_HOME
    $ maglev start
  3. Install necessary gems:

    $ cd <to this directory>
    $ $MAGLEV_HOME/bin/bundle install
    
    ### Temporary workaround for https://magtrac.gemstone.com/ticket/879 ###
    $ maglev-gem pristine rack

Viewing Ruby code

Run the WebTools Sinatra application

$ rake

This will start WEBrick in your current window. Hit Ctl-C to stop.

Browse to localhost:9292/, click on a class or module, then click on a constant or method. Results appear in the bottom pane, file locations with line numbers in the bottom status line, and time spent on the server/network/client in the top status line.

Add classes and modules from ActiveModel

WARNING: If you already have an application loaded into MagLev, do not run rake meta since it persists RubyGems and ActiveModel. Use WebTools to explore your application instead. If you run rake meta, run maglev force-reload afterwards to load an empty database.

$ rake meta

Click on “Refresh View” in WebTools. Note that AValidPerson now appears in the class list, as do a number of classes/modules from ActiveModel and ActiveSupport.

Click on the class AValidPerson and compare it with the source (meta_demo.rb). Some things to note:

  1. You can see all the methods generated by metaprogramming.

  2. You can see the file and line number of the code that generated each method. This makes it simpler to track down which part of ActiveWhatever is messing with your code.

  3. The initialize method is unchanged from the code in meta_demo.rb

  4. The instance method _callback_before_1 generated from $MAGLEV_HOME/lib/maglev/gems/1.8/gems/activesupport-3.0.5/lib/active_support/callbacks.rb shows the actual method name _callback_before_1 instead of #{method_name}.

Modify meta_demo.rb and view new generated methods

Edit the file meta_demo.rb. Add :age to both validates_presence_of and attr_accessor. The changed lines should look like

validates_presence_of :first_name, :last_name, :age
attr_accessor :first_name, :last_name, :age

Then

$ rake meta

Click on “Refresh View” in WebTools. AValidPerson will now include the new instance methods age and age=.

Add some data

$ rake demodata

Click on “Refresh View” in WebTools. Note that AAADemo now appears in the class list. Click on the class AAADemo and compare it with the source (demo_data.rb).

Viewing GemStone/S code, processes and statistics

The code for this example was inspired by the Smalltalk example found in $MAGLEV_HOME/gemstone/examples/www. The Smalltalk example code can be invoked from ruby (a demonstration of how to invoke Smalltalk from Ruby), via:

$ rake smalltalk

Then browse to localhost:8080/ and explore

Hit Ctl-C in the terminal window to stop.

Known problems

Network timeouts are not caught. EAGAIN is not handled. If you're running WebTools on a slow network, this may cause data to not appear in the bottom pane.

The line number displayed for evals is always 2. This will be fixed at a later date.

Contributing

  • Fork the project from github.com/MagLev/webtools

  • Start a feature or topic branch

  • Commit and push until you are happy with your contribution

  • Add some tests to ensure we don't break things in a future release

  • Make sure to test with the latest MagLev

  • Send a pull request

MagLev Ruby code in this project is MIT licensed. See LICENSE.txt in this directory. By sending a pull request, you agree your contributed code is also MIT licensed.

This project includes a copy of CodeMirror, copyrighted by Marijn Haverbeke. See public/CodeMirror/LICENSE.

Something went wrong with that request. Please try again.