Class: Danger::DangerSynx
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerSynx
- Defined in:
- lib/synx/plugin.rb
Overview
Enforces that .xcodeproj structure is tidy. It wraps around [Synx](github.com/venmo/synx) tool to perform the check.
Instance Method Summary collapse
-
#ensure_clean_structure ⇒ void
Ensures clean project structure.
-
#precheck_synx_installation? ⇒ bool
Checks whether Synx in a correct version is installed in the system.
-
#synx ⇒ String
Returns a command to run for synx.
-
#synx_installed? ⇒ bool
Tests whether Synx is already installed and meets minimal version requirements.
-
#synx_issues ⇒ Array<(String, String)>
Triggers Synx on all projects that were modified or added to the project.
-
#synx_project(modified_file_path) ⇒ (String, String)
Triggers Synx in a dry-run mode on a project file.
Instance Method Details
#ensure_clean_structure ⇒ void
This method returns an undefined value.
Ensures clean project structure. Runs Synx on all .xcodeproj files that where either added or modified.
19 20 21 22 23 24 25 |
# File 'lib/synx/plugin.rb', line 19 def ensure_clean_structure unless synx_installed? raise 'synx > 0.2.1 not found in PATH and failed to install' end generate_output synx_issues end |
#precheck_synx_installation? ⇒ bool
Checks whether Synx in a correct version is installed in the system. If not, tries to recover by installing it. Returns true if Synx is present or installation was successful.
33 34 35 36 |
# File 'lib/synx/plugin.rb', line 33 def precheck_synx_installation? `gem install synx` unless synx_installed? synx_installed? end |
#synx ⇒ String
Returns a command to run for synx
41 42 43 |
# File 'lib/synx/plugin.rb', line 41 def synx "#{'bundle exec ' if File.exist?('Gemfile')}synx" end |
#synx_installed? ⇒ bool
Tests whether Synx is already installed and meets minimal version requirements.
50 51 52 53 54 55 56 57 58 |
# File 'lib/synx/plugin.rb', line 50 def synx_installed? match = `#{synx} --version`.match(/Synx (\d+)\.(\d+)\.(\d+)/i) if match major, minor, patch = match.captures.map { |c| Integer(c) } major > 0 || minor > 2 || (minor == 2 && patch > 1) else false end end |
#synx_issues ⇒ Array<(String, String)>
Triggers Synx on all projects that were modified or added to the project. Returns accumulated list of issues for those projects.
66 67 68 69 70 |
# File 'lib/synx/plugin.rb', line 66 def synx_issues (git.modified_files + git.added_files) .select { |f| f.include? '.xcodeproj' } .reduce([]) { |i, f| i + synx_project(f) } end |
#synx_project(modified_file_path) ⇒ (String, String)
Triggers Synx in a dry-run mode on a project file. Parses output and returns a list of issues.
80 81 82 83 84 85 86 87 88 |
# File 'lib/synx/plugin.rb', line 80 def synx_project(modified_file_path) path = project_path modified_file_path name = project_name path output = `#{synx} -w warning "#{path}" 2>&1`.lines output .map(&:strip) .select { |o| o.start_with? 'warning: ' } .map { |o| [name, strip_prefix(o)] } end |