Project

code_web

0.0
No commit activity in last 3 years
No release in over 3 years
Display the web of method calls in an app
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

 Project Readme

CodeWeb

This uses ruby parser to read code with static analysis and find references. Works best when looking for finding static methods that possibly span multiple lines

It is not smart enough to understand return types.

For hashes/positional arguments, it displays the hash arguments. It only works when actual hash parameters are passed vs variables or splats.

It generates an html file with the list of each method and the invocations. Each reference has a url to the place in code where it is found.

The urls use textmate url format, which also works with sublime. I use lincastor on my machine to wire the urls to the actual editor, so any program will do.

Installation

Add this line to your application's Gemfile:

gem 'code_web'

And then execute:

$ bundle

Or install it yourself as:

$ gem install code_web

Usage

# if you find the reference in a file named miq_queue.rb, then color the url with #999
# if you find the reference in a file with the director tools, then color the url with #ccc 
# look for the class name MiqQueue
# look in the directories app, tools, and lib
# output the report to miq_queue.html (in html format)

$ code_web -p 'miq_queue.rb$=#999' -p 'tools/=#ccc' 'MiqQueue\b' app tools lib -o miq_queue.html


# find calls to User.select
$ code_web 'User.select\b' lib -o user_select.html


# generate links pointing to github (instead of local sublime)
$ code_web --url https://github.com/ManageIQ/manageiq/blob/master --byebug 'MiqQueue' app lib/vmdb -o miq_queue.html

Url handline

Currently, this generates urls using the textmate file protocol.

I use LinCastor to map the url to my editor of choice, sublime. But there are many tools that will do this for you. LinCastor has worked for many many years, including my current version, 10.12.3

I use the following script to wire it together:

#!/usr/bin/ruby

# Parse a url according to 
# http://blog.macromates.com/2007/the-textmate-url-scheme/
# opens the file

SUBL_PATH="/Applications/Sublime Text.app"
SUBL_BIN_PATH="#{SUBL_PATH}/Contents/SharedSupport/bin/subl"

#require 'logger'
require 'uri'
require 'cgi'

#DEBUG = Logger.new(File.open("#{ENV['HOME']}/sublime_cmd.txt", File::WRONLY | File::APPEND|File::CREAT))

subl_url=ENV['URL']
p=CGI.parse(URI.parse(subl_url).query)
subl_file="#{p["url"].first[7..-1]}:#{p["line"].first}"

#DEBUG.info(subl_file)

ret=`"#{SUBL_BIN_PATH}" "#{subl_file}"`
#DEBUG.info("#{SUBL_BIN_PATH} #{subl_file}")
#DEBUG.info("/handle_url")

exit 0 # the handler has finished successfully

I left the debugging statements in there to help you if there are issues

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request