Commit 38c055de20d223519839a51224ce116ae03da15d

Authored by Luciano Prestes
Committed by Thiago Ribeiro
1 parent 202f0213

Refactor software_communities methods

Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
controllers/software_communities_plugin_controller.rb
@@ -42,11 +42,7 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController @@ -42,11 +42,7 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController
42 protected 42 protected
43 43
44 def get_model_by_params_field 44 def get_model_by_params_field
45 - case params[:field]  
46 - when "software_language"  
47 - return ProgrammingLanguage  
48 - else  
49 - return DatabaseDescription  
50 - end 45 + return DatabaseDescription unless params[:field] == "software_language"
  46 + return ProgrammingLanguage
51 end 47 end
52 end 48 end
controllers/software_communities_plugin_myprofile_controller.rb
@@ -26,7 +26,7 @@ class SoftwareCommunitiesPluginMyprofileController &lt; MyProfileController @@ -26,7 +26,7 @@ class SoftwareCommunitiesPluginMyprofileController &lt; MyProfileController
26 26
27 return unless request.post? 27 return unless request.post?
28 28
29 - @software_info = constroy_software 29 + @software_info = create_software
30 software_info_insert_models.call(@list_libraries, 'libraries') 30 software_info_insert_models.call(@list_libraries, 'libraries')
31 software_info_insert_models.call(@list_languages, 'software_languages') 31 software_info_insert_models.call(@list_languages, 'software_languages')
32 software_info_insert_models.call(@list_databases, 'software_databases') 32 software_info_insert_models.call(@list_databases, 'software_databases')
@@ -87,7 +87,7 @@ class SoftwareCommunitiesPluginMyprofileController &lt; MyProfileController @@ -87,7 +87,7 @@ class SoftwareCommunitiesPluginMyprofileController &lt; MyProfileController
87 } 87 }
88 end 88 end
89 89
90 - def constroy_software 90 + def create_software
91 @software_info = @profile.software_info 91 @software_info = @profile.software_info
92 params[:software][:public_software] ||= false unless @software_info.public_software? 92 params[:software][:public_software] ||= false unless @software_info.public_software?
93 @license = LicenseInfo.find(params[:license][:license_infos_id]) 93 @license = LicenseInfo.find(params[:license][:license_infos_id])
lib/database_helper.rb
@@ -34,12 +34,7 @@ class DatabaseHelper &lt; DynamicTableHelper @@ -34,12 +34,7 @@ class DatabaseHelper &lt; DynamicTableHelper
34 34
35 def self.valid_list_database? list_databases 35 def self.valid_list_database? list_databases
36 return false if list_databases.nil? or list_databases.length == 0 36 return false if list_databases.nil? or list_databases.length == 0
37 -  
38 - list_databases.each do |database|  
39 - return false unless database.valid?  
40 - end  
41 -  
42 - true 37 + return !list_databases.any?{|database| !database.valid?}
43 end 38 end
44 39
45 def self.database_as_tables(list_databases, disabled=false) 40 def self.database_as_tables(list_databases, disabled=false)
@@ -51,14 +46,10 @@ class DatabaseHelper &lt; DynamicTableHelper @@ -51,14 +46,10 @@ class DatabaseHelper &lt; DynamicTableHelper
51 46
52 def self.database_html_structure(database_data, disabled) 47 def self.database_html_structure(database_data, disabled)
53 database_id = database_data[:database_description_id] 48 database_id = database_data[:database_description_id]
54 - database_name = if database_data[:database_description_id].blank?  
55 - ""  
56 - else  
57 - DatabaseDescription.find( 49 + database_name = database_id.blank? ? "" : DatabaseDescription.find(
58 database_data[:database_description_id], 50 database_data[:database_description_id],
59 :select=>"name" 51 :select=>"name"
60 ).name 52 ).name
61 - end  
62 53
63 data = { 54 data = {
64 model_name: MODEL_NAME, 55 model_name: MODEL_NAME,
@@ -83,4 +74,4 @@ class DatabaseHelper &lt; DynamicTableHelper @@ -83,4 +74,4 @@ class DatabaseHelper &lt; DynamicTableHelper
83 def self.add_dynamic_table 74 def self.add_dynamic_table
84 database_as_tables(nil).first.call 75 database_as_tables(nil).first.call
85 end 76 end
86 -end  
87 \ No newline at end of file 77 \ No newline at end of file
  78 +end
lib/library_helper.rb
@@ -20,12 +20,7 @@ class LibraryHelper &lt; DynamicTableHelper @@ -20,12 +20,7 @@ class LibraryHelper &lt; DynamicTableHelper
20 20
21 def self.valid_list_library? list_libraries 21 def self.valid_list_library? list_libraries
22 return true if list_libraries.nil? or list_libraries.length == 0 22 return true if list_libraries.nil? or list_libraries.length == 0
23 -  
24 - list_libraries.each do |library|  
25 - return false unless library.valid?  
26 - end  
27 -  
28 - true 23 + return !list_libraries.any?{|library| !library.valid?}
29 end 24 end
30 25
31 def self.libraries_as_tables list_libraries, disabled=false 26 def self.libraries_as_tables list_libraries, disabled=false
@@ -59,4 +54,4 @@ class LibraryHelper &lt; DynamicTableHelper @@ -59,4 +54,4 @@ class LibraryHelper &lt; DynamicTableHelper
59 def self.add_dynamic_table 54 def self.add_dynamic_table
60 libraries_as_tables(nil).first.call 55 libraries_as_tables(nil).first.call
61 end 56 end
62 -end  
63 \ No newline at end of file 57 \ No newline at end of file
  58 +end
lib/operating_system_helper.rb
@@ -25,12 +25,8 @@ class OperatingSystemHelper &lt; DynamicTableHelper @@ -25,12 +25,8 @@ class OperatingSystemHelper &lt; DynamicTableHelper
25 end 25 end
26 26
27 def self.valid_list_operating_system? list_operating_system 27 def self.valid_list_operating_system? list_operating_system
28 - return !(list_operating_system.nil? || list_operating_system.length == 0)  
29 -  
30 - list_operating_system.each do |operating_system|  
31 - return false unless operating_system.valid?  
32 - end  
33 - true 28 + return false if (list_operating_system.nil? || list_operating_system.length == 0)
  29 + return !list_operating_system.any?{|os| !os.valid?}
34 end 30 end
35 31
36 def self.operating_system_as_tables(list_operating_system, disabled=false) 32 def self.operating_system_as_tables(list_operating_system, disabled=false)
lib/software_communities_plugin.rb
@@ -18,8 +18,8 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -18,8 +18,8 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
18 end 18 end
19 19
20 def profile_tabs 20 def profile_tabs
21 - if context.profile.community?  
22 - return profile_tabs_software if context.profile.software? 21 + if context.profile.community? && context.profile.software?
  22 + return profile_tabs_software
23 end 23 end
24 end 24 end
25 25
lib/software_helper.rb
@@ -23,14 +23,6 @@ module SoftwareHelper @@ -23,14 +23,6 @@ module SoftwareHelper
23 end 23 end
24 24
25 def self.all_table_is_empty? table, ignored_fields=[] 25 def self.all_table_is_empty? table, ignored_fields=[]
26 - filled_fields = []  
27 -  
28 - table.each do |key, value|  
29 - unless ignored_fields.include? key  
30 - filled_fields << !value.empty?  
31 - end  
32 - end  
33 -  
34 - return !filled_fields.include?(true) 26 + return !table.keys.any?{|key| ignored_fields.include?(key) ? false : !table[key].empty?}
35 end 27 end
36 end 28 end