26. config/routes.rb
match ‘/’, :to => ‘root#index’
match ‘root’, :to => ‘root#index’
namespace :admin do
resources :grids do
resources :nodes
resources :edges do
collection do
post :all
post :update_all
end
end
resources :walkers
end
end
resources :nodes, :only => [:show,:new,:create,:destroy] do
put :directions, :on => :collection
end
resources :walkers, :only => [:show,:new,:create,:destroy] do
get :select, :on => :collection
end
resources :itineraries, :only => [:show]
Tuesday 8 June 2010 map.four_oh_four '*path' , :controller => 'four_oh_fours'
39. FLOG
Assignment Branch Condition (ABC)
def score_method(tally)
a, b, c = 0, 0, 0
tally.each do |cat, score|
case cat
when :assignment then a += score
when :branch then b += score
else c += score
end
end
Math.sqrt(a*a + b*b + c*c)
end
Tuesday 8 June 2010
40. FLOG
Weighing the AST with factors
def process_if(exp)
add_to_score :branch
process exp.shift # cond
penalize_by 0.1 do
process exp.shift # true
process exp.shift # false
end
s()
end
Tuesday 8 June 2010
41. FLOG
Very good: < 20
All Right: < 50
Tuesday 8 June 2010
43. FLAY
flay *.rb
Total score (lower is better) = 621
1) IDENTICAL code found in :defn (mass*2 = 188)
channel.rb:48
clip.rb:80
2) Similar code found in :defn (mass = 93)
channel.rb:150
clip.rb:110
clip.rb:116
3) Similar code found in :defs (mass = 58)
contact.rb:32
contact.rb:37
Tuesday 8 June 2010
44. FLAY
RubyParser
def mass
@mass ||= self.structure.flatten.size
end
Hash of structure of nodes with mass >
threshold
self.hashes[node.structural_hash] << node
analyze:
if same hash = similar
if same node = identical
Tuesday 8 June 2010
45. Saikuro
cyclomatic
complexity
Tuesday 8 June 2010
47. Saikuro
ruby-lex
every keyword is interpreted into
‘state’
state used to calculate
if, unless, while, until, for, elsif, when, rescue
(blocks)
Recursively
Tuesday 8 June 2010
49. Roodi
‘Ruby Object Oriented Design Inferometer’
nutmeg66 on flickr
Tuesday 8 June 2010
50. Roodi
app/controllers/itineraries_controller.rb:4 - Method name "show" cyclomatic complexity
is 14. It should be 8 or less.
app/models/itinerary.rb:41 - Block cyclomatic complexity is 6. It should be 4 or less.
app/controllers/itineraries_controller.rb:4 - Method "show" has 30 lines. It should
have 20 or less.
app/helpers/application_helper.rb:27 - Method "clippy" has 26 lines. It should have 20
or less.
Tuesday 8 June 2010
53. Reek
UserSessionsController has no descriptive comment (Irresponsible Module)
UserSessionsController#destroy calls current_user_session twice
(Duplication)
app/controllers/users_controller.rb -- 5 warnings:
UsersController has no descriptive comment (Irresponsible Module)
UsersController tests @aid_app at least 4 times (Simulated Polymorphism)
UsersController#create calls params 3 times (Duplication)
UsersController#create calls params[:user] 3 times (Duplication)
...
Tuesday 8 June 2010
54. Reek
OO Code smells
Control Couple
Data Clump
Feature Envy
Large Class
Long Method
Long Parameter List
Simulated Polymorphism
Uncommunicative Name
Tuesday 8 June 2010
55. Reek
RubyParser
extends parsed nodes
traverses nodes
returns code after Ruby2Ruby
Tuesday 8 June 2010
57. rails_best_practices
./app/controllers/ws/vmg/aid_user_accounts_controller.rb:160 - move model logic into model
(@aid_user_account called_count > 4)
./app/controllers/ws/vmg/ipt_controller.rb:102 - move model logic into model (xml
called_count > 4)
./app/controllers/ws/vmg/ipt_controller.rb:102 - move model logic into model (pf
called_count > 4)
./config/routes.rb:3 - overuse route customizations (customize_count > 3)
./config/routes.rb:35 - overuse route customizations (customize_count > 3)
./app/models/vmg/scenario.rb:41 - keep finders on their own model
Tuesday 8 June 2010
60. Churn
Not only classes but also methods
(RubyParser)
Version control: git, Hg, svn
Locates changes in source using logs
(as in git log)
Tuesday 8 June 2010