diff --git a/.gitignore b/.gitignore index d71fa9c..af41656 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .idea/workspace.xml .rakeTasks encodings.xml +Gemfile.lock diff --git a/lib/generamba/helpers/dependency_checker.rb b/lib/generamba/helpers/dependency_checker.rb index 82ffa95..d49343e 100644 --- a/lib/generamba/helpers/dependency_checker.rb +++ b/lib/generamba/helpers/dependency_checker.rb @@ -1,17 +1,15 @@ require 'cocoapods-core' module Generamba - # Provides methods for check dependencies from rambaspec in podfile class DependencyChecker - # Check Podfile for dependencies # @param dependencies [Array] Array of dependencies name # @param podfile_path [String] String of Podfile path # # @return [void] def self.check_all_required_dependencies_has_in_podfile(dependencies, podfile_path) - return if !dependencies or dependencies.count == 0 or !podfile_path + return if !dependencies || dependencies.count == 0 || !podfile_path dependencies_names = [] Pod::Podfile.from_file(Pathname.new(podfile_path)).dependencies.each do |dependency| @@ -37,7 +35,7 @@ def self.check_all_required_dependencies_has_in_podfile(dependencies, podfile_pa # # @return [void] def self.check_all_required_dependencies_has_in_cartfile(dependencies, cartfile_path) - return if !dependencies or dependencies.count == 0 or !cartfile_path + return if !dependencies || dependencies.count == 0 || !cartfile_path cartfile_string = File.read(cartfile_path) @@ -52,7 +50,5 @@ def self.check_all_required_dependencies_has_in_cartfile(dependencies, cartfile_ puts "[Warning] Dependencies #{not_existing_dependency} missed in Cartfile".yellow end end - end - -end \ No newline at end of file +end diff --git a/lib/generamba/helpers/gen_command_table_parameters_formatter.rb b/lib/generamba/helpers/gen_command_table_parameters_formatter.rb index c39846d..448ee2e 100644 --- a/lib/generamba/helpers/gen_command_table_parameters_formatter.rb +++ b/lib/generamba/helpers/gen_command_table_parameters_formatter.rb @@ -1,8 +1,6 @@ module Generamba - # Provides methods for prepare parameters for displaying in table. class GenCommandTableParametersFormatter - # This method prepared parameter for displaying def self.prepare_parameters_for_displaying(parameters) params = parameters.clone @@ -15,9 +13,7 @@ def self.prepare_parameters_for_displaying(parameters) params['templates'] = templates.join("\n") - return params + params end - end - end diff --git a/lib/generamba/helpers/print_table.rb b/lib/generamba/helpers/print_table.rb index aa69837..baca92b 100644 --- a/lib/generamba/helpers/print_table.rb +++ b/lib/generamba/helpers/print_table.rb @@ -1,8 +1,6 @@ module Generamba - # Provides methods for print parameters in nice table. class PrintTable - # This method prints out all the user inputs in a nice table. def self.print_values(values: nil, title: nil) require 'terminal-table' @@ -15,7 +13,5 @@ def self.print_values(values: nil, title: nil) puts Terminal::Table.new(params) puts '' end - end - -end \ No newline at end of file +end diff --git a/lib/generamba/helpers/rambafile_validator.rb b/lib/generamba/helpers/rambafile_validator.rb index b1ea69b..8ed133a 100644 --- a/lib/generamba/helpers/rambafile_validator.rb +++ b/lib/generamba/helpers/rambafile_validator.rb @@ -1,8 +1,6 @@ module Generamba - # Provides methods for validating Rambafile contents class RambafileValidator - # Method validates Rambafile contents # @param path [String] The path to a Rambafile # @@ -44,7 +42,7 @@ def validate(path) # # @return [Array] def all_project_failure_fields(preferences) - return all_nil_mandatory_fields_for_target_type("project", preferences) + all_nil_mandatory_fields_for_target_type('project', preferences) end # Method which return all test failure fields @@ -59,23 +57,21 @@ def all_test_failure_fields(preferences) has_test_fields = target || targets || file_path || group_path - unless has_test_fields - return [] - end - - return all_nil_mandatory_fields_for_target_type("test", preferences) + return [] unless has_test_fields + + all_nil_mandatory_fields_for_target_type('test', preferences) end # Method which return all failure fields for target_type # @param target_type [String] "project" or "test" # @param preferences [Hash] Converted Rambafile - # + # # @return [Array] def all_nil_mandatory_fields_for_target_type(target_type, preferences) target_type = target_type.upcase - target_const_value = Generamba.const_get(target_type + "_TARGET_KEY") - targets_const_value = Generamba.const_get(target_type + "_TARGETS_KEY") + target_const_value = Generamba.const_get(target_type + '_TARGET_KEY') + targets_const_value = Generamba.const_get(target_type + '_TARGETS_KEY') target = preferences[target_const_value] targets = preferences[targets_const_value] @@ -86,20 +82,19 @@ def all_nil_mandatory_fields_for_target_type(target_type, preferences) fields.push(target_const_value) end - file_path_const_value = Generamba.const_get(target_type + "_FILE_PATH_KEY") + file_path_const_value = Generamba.const_get(target_type + '_FILE_PATH_KEY') unless preferences[file_path_const_value] fields.push(file_path_const_value) - end + end - group_path_const_value = Generamba.const_get(target_type + "_GROUP_PATH_KEY") + group_path_const_value = Generamba.const_get(target_type + '_GROUP_PATH_KEY') unless preferences[group_path_const_value] fields.push(group_path_const_value) end - return fields + fields end - end -end \ No newline at end of file +end diff --git a/lib/generamba/helpers/template_helper.rb b/lib/generamba/helpers/template_helper.rb index 54aa0d5..81ede3a 100644 --- a/lib/generamba/helpers/template_helper.rb +++ b/lib/generamba/helpers/template_helper.rb @@ -1,8 +1,6 @@ module Generamba - # Provides a number of helper methods for manipulating Generamba template files class TemplateHelper - # Returns a file path for a specific template .rambaspec file # @param template_name [String] The Generamba template name # @@ -11,7 +9,7 @@ def self.obtain_spec(template_name) template_path = self.obtain_path(template_name) spec_path = template_path.join(template_name + RAMBASPEC_EXTENSION) - return spec_path + spec_path end # Returns a file path for a specific template folder @@ -20,13 +18,13 @@ def self.obtain_spec(template_name) # @return [Pathname] def self.obtain_path(template_name) path = Pathname.new(Dir.getwd) - .join(TEMPLATES_FOLDER) - .join(template_name) + .join(TEMPLATES_FOLDER) + .join(template_name) error_description = "Cannot find template named #{template_name}! Add it to the Rambafile and run *generamba template install*".red - raise StandardError.new(error_description) unless path.exist? + raise StandardError, error_description unless path.exist? - return path + path end end -end \ No newline at end of file +end diff --git a/lib/generamba/helpers/xcodeproj_helper.rb b/lib/generamba/helpers/xcodeproj_helper.rb index c7fc1d8..0a0702c 100644 --- a/lib/generamba/helpers/xcodeproj_helper.rb +++ b/lib/generamba/helpers/xcodeproj_helper.rb @@ -1,8 +1,6 @@ module Generamba - # Provides a number of helper methods for working with xcodeproj gem class XcodeprojHelper - # Returns a PBXProject class for a given name # @param project_name [String] The name of the project file # @@ -20,23 +18,23 @@ def self.obtain_project(project_name) # # @return [void] def self.add_file_to_project_and_targets(project, targets_name, group_path, file_path, file_type = nil) - module_group = self.retrieve_group_or_create_if_needed(group_path, project, true) + module_group = retrieve_group_or_create_if_needed(group_path, project, true) xcode_file = module_group.new_file(File.absolute_path(file_path)) file_name = File.basename(file_path) targets_name.each do |target| - xcode_target = self.obtain_target(target, project) + xcode_target = obtain_target(target, project) unless file_type - if self.is_compile_source?(file_name) + if is_compile_source?(file_name) file_type = 'source' - elsif self.is_bundle_resource?(file_name) + elsif is_bundle_resource?(file_name) file_type = 'resource' end end - if file_type != nil - self.add_file_to_target(xcode_target, xcode_file, file_type) + unless file_type.nil? + add_file_to_target(xcode_target, xcode_file, file_type) end end end @@ -49,7 +47,7 @@ def self.add_file_to_project_and_targets(project, targets_name, group_path, file def self.add_group_to_project(project, group_path) self.retrieve_group_or_create_if_needed(group_path, project, true) end - + # Adds xcode file to target based on it's type # @param target [Xcodeproj::AbstractTarget] xcode target to use # @param file [Xcodeproj::PBXFileReference] file reference to add @@ -57,12 +55,12 @@ def self.add_group_to_project(project, group_path) # def self.add_file_to_target(target, file, type) case type - when 'source' - target.add_file_references([file]) - when 'resource' - target.add_resources([file]) - else - puts "Can't add file with type #{type}. Only 'source' and 'resource' are acceptable" + when 'source' + target.add_file_references([file]) + when 'resource' + target.add_resources([file]) + else + puts "Can't add file with type #{type}. Only 'source' and 'resource' are acceptable" end end @@ -97,7 +95,7 @@ def self.clear_group(project, targets_name, group_path) files_path.each do |file_path| self.remove_file_by_file_path(file_path, targets_name, project) end - + module_group.clear end @@ -108,7 +106,7 @@ def self.clear_group(project, targets_name, group_path) # @return [TrueClass or FalseClass] def self.module_with_group_path_already_exists(project, group_path) module_group = self.retrieve_group_or_create_if_needed(group_path, project, false) - return module_group == nil ? false : true + module_group.nil? ? false : true end private @@ -128,9 +126,7 @@ def self.retrieve_group_or_create_if_needed(group_path, project, create_group_if next_group = final_group[group_name] unless next_group - unless create_group_if_not_exists - return nil - end + return nil unless create_group_if_not_exists new_group_path = group_name next_group = final_group.new_group(group_name, new_group_path) @@ -138,8 +134,7 @@ def self.retrieve_group_or_create_if_needed(group_path, project, create_group_if final_group = next_group end - - return final_group + final_group end # Returns an AbstractTarget class for a given name @@ -149,13 +144,11 @@ def self.retrieve_group_or_create_if_needed(group_path, project, create_group_if # @return [Xcodeproj::AbstractTarget] def self.obtain_target(target_name, project) project.targets.each do |target| - if target.name == target_name - return target - end + return target if target.name == target_name end error_description = "Cannot find a target with name #{target_name} in Xcode project".red - raise StandardError.new(error_description) + raise StandardError, error_description end # Splits the provided Xcode path to an array of separate paths @@ -163,8 +156,7 @@ def self.obtain_target(target_name, project) # # @return [[String]] def self.path_names_from_path(path) - paths = path.to_s.split('/') - return paths + path.to_s.split('/') end # Remove build file from target build phase @@ -188,7 +180,7 @@ def self.remove_file_by_file_path(file_path, targets_name, project) end def self.remove_file_from_build_phases(file_path, build_phases) - return if build_phases == nil + return if build_phases.nil? build_phases.each do |build_phase| build_phase.files.each do |build_file| @@ -220,7 +212,7 @@ def self.build_phases_from_targets(targets_name, project) end end - return build_phases + build_phases end # Find and return target resources build phase @@ -236,7 +228,7 @@ def self.resources_build_phase_from_targets(targets_name, project) resource_build_phase.push(xcode_target.resources_build_phase) end - return resource_build_phase + resource_build_phase end # Get configure file full path @@ -247,7 +239,7 @@ def self.configure_file_ref_path(file_ref) build_file_ref_path = file_ref.hierarchy_path.to_s build_file_ref_path[0] = '' - return build_file_ref_path + build_file_ref_path end # Get all files path from group path @@ -255,18 +247,17 @@ def self.configure_file_ref_path(file_ref) # @param project [Xcodeproj::Project] The target xcodeproj file # # @return [[String]] - def self.files_path_from_group(module_group, project) + def self.files_path_from_group(module_group, _project) files_path = [] module_group.recursive_children.each do |file_ref| if file_ref.isa == 'PBXFileReference' - file_ref_path = self.configure_file_ref_path(file_ref) + file_ref_path = configure_file_ref_path(file_ref) files_path.push(file_ref_path) end end - return files_path + files_path end - end -end \ No newline at end of file +end