Commit 1c5cceaf3cbdd7822ef458f0b4daac83647d759e
Committed by
Paulo Meireles
1 parent
904366d7
Exists in
staging
and in
42 other branches
[Mezuro] Refactored node_of and get_node methods.
Showing
3 changed files
with
13 additions
and
23 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
| @@ -56,7 +56,7 @@ class MezuroPluginProfileController < ProfileController | @@ -56,7 +56,7 @@ class MezuroPluginProfileController < ProfileController | ||
| 56 | if project_content_has_errors? | 56 | if project_content_has_errors? |
| 57 | redirect_to_error_page(@content.errors[:base]) | 57 | redirect_to_error_page(@content.errors[:base]) |
| 58 | else | 58 | else |
| 59 | - @source_tree = project_result.node_of(params[:module_name]) | 59 | + @source_tree = project_result.node(params[:module_name]) |
| 60 | render :partial =>'content_viewer/source_tree' | 60 | render :partial =>'content_viewer/source_tree' |
| 61 | end | 61 | end |
| 62 | end | 62 | end |
plugins/mezuro/lib/kalibro/project_result.rb
| @@ -75,21 +75,17 @@ class Kalibro::ProjectResult < Kalibro::Model | @@ -75,21 +75,17 @@ class Kalibro::ProjectResult < Kalibro::Model | ||
| 75 | ('%2d' % amount).sub(/\s/, '0') | 75 | ('%2d' % amount).sub(/\s/, '0') |
| 76 | end | 76 | end |
| 77 | 77 | ||
| 78 | - def node_of(module_name) | 78 | + def node(module_name) |
| 79 | if module_name.nil? or module_name == project.name | 79 | if module_name.nil? or module_name == project.name |
| 80 | node = source_tree | 80 | node = source_tree |
| 81 | else | 81 | else |
| 82 | - node = get_node(module_name) | ||
| 83 | - end | ||
| 84 | - end | ||
| 85 | - | ||
| 86 | - def get_node(module_name) | ||
| 87 | - path = Kalibro::Module.parent_names(module_name) | ||
| 88 | - parent = @source_tree | ||
| 89 | - path.each do |node_name| | ||
| 90 | - parent = get_leaf_from(parent, node_name) | ||
| 91 | - end | ||
| 92 | - return parent | 82 | + path = Kalibro::Module.parent_names(module_name) |
| 83 | + parent = @source_tree | ||
| 84 | + path.each do |node_name| | ||
| 85 | + parent = get_leaf_from(parent, node_name) | ||
| 86 | + end | ||
| 87 | + parent | ||
| 88 | + end | ||
| 93 | end | 89 | end |
| 94 | 90 | ||
| 95 | private | 91 | private |
plugins/mezuro/test/unit/kalibro/project_result_test.rb
| @@ -69,26 +69,20 @@ class ProjectResultTest < ActiveSupport::TestCase | @@ -69,26 +69,20 @@ class ProjectResultTest < ActiveSupport::TestCase | ||
| 69 | assert_equal '00:00:01', @project_result.formatted_analysis_time | 69 | assert_equal '00:00:01', @project_result.formatted_analysis_time |
| 70 | end | 70 | end |
| 71 | 71 | ||
| 72 | - should 'retrieve module node' do | ||
| 73 | - node = @project_result.get_node("main") | ||
| 74 | - assert_equal @hash[:source_tree][:child][2], node.to_hash | ||
| 75 | - end | ||
| 76 | - | ||
| 77 | should 'retrive complex module' do | 72 | should 'retrive complex module' do |
| 78 | - node = @project_result.get_node("org.Window") | ||
| 79 | - assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash | 73 | + assert_equal @hash[:source_tree][:child][0][:child].first, @project_result.node("org.Window").to_hash |
| 80 | end | 74 | end |
| 81 | 75 | ||
| 82 | should 'return source tree node when nil is given' do | 76 | should 'return source tree node when nil is given' do |
| 83 | - assert_equal @hash[:source_tree], @project_result.node_of(nil).to_hash | 77 | + assert_equal @hash[:source_tree], @project_result.node(nil).to_hash |
| 84 | end | 78 | end |
| 85 | 79 | ||
| 86 | should 'return source tree node when project name is given' do | 80 | should 'return source tree node when project name is given' do |
| 87 | - assert_equal @hash[:source_tree], @project_result.node_of(@project_result.project.name).to_hash | 81 | + assert_equal @hash[:source_tree], @project_result.node(@project_result.project.name).to_hash |
| 88 | end | 82 | end |
| 89 | 83 | ||
| 90 | should 'return correct node when module name is given' do | 84 | should 'return correct node when module name is given' do |
| 91 | - assert_equal @hash[:source_tree][:child][2], @project_result.node_of("main").to_hash | 85 | + assert_equal @hash[:source_tree][:child][2], @project_result.node("main").to_hash |
| 92 | end | 86 | end |
| 93 | 87 | ||
| 94 | end | 88 | end |