Class: DiffTest::Configuration
- Inherits:
-
Object
- Object
- DiffTest::Configuration
- Defined in:
- lib/diff_test/configuration.rb
Instance Attribute Summary collapse
- #api_key ⇒ Object
- #base_api_url ⇒ Object
- #enabled(&block) ⇒ Object
- #ignored_files ⇒ Object
- #project_files ⇒ Object
- #project_root ⇒ Object
-
#run_on_main_branch ⇒ Object
writeonly
Sets the attribute run_on_main_branch.
- #tracked_files ⇒ Object
- #tracked_js_files ⇒ Object
- #vendor_bundle_path ⇒ Object
Instance Method Summary collapse
- #auto_annotate_js_files ⇒ Object
- #auto_annotate_js_files=(value) ⇒ Object
- #auto_annotate_js_files? ⇒ Boolean
- #ci_platform ⇒ Object
- #enabled? ⇒ Boolean
- #integratable? ⇒ Boolean
- #port ⇒ Object
- #run_on_main_branch? ⇒ Boolean
- #system_test_paths ⇒ Object
Instance Attribute Details
#api_key ⇒ Object
15 16 17 |
# File 'lib/diff_test/configuration.rb', line 15 def api_key @api_key || ENV['DIFF_TEST_API_KEY'] end |
#base_api_url ⇒ Object
174 175 176 |
# File 'lib/diff_test/configuration.rb', line 174 def base_api_url @base_api_url || "https://diff-test.owaiskhan.me" end |
#enabled(&block) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/diff_test/configuration.rb', line 116 def enabled(&block) if block_given? @enabled = block else @enabled end end |
#ignored_files ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/diff_test/configuration.rb', line 54 def ignored_files ||= begin @ignored_files ||= ['db/migrate/**/*', '**/*.md'] filter_from_project_files(@ignored_files) end end |
#project_files ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/diff_test/configuration.rb', line 45 def project_files ||= begin @project_files ||= [-> { `git -C "#{project_root}" ls-files`.split("\n") }] (@project_files) end end |
#project_root ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/diff_test/configuration.rb', line 23 def project_root return @project_root.freeze if @project_root @project_root = ::Rails.root.to_s.freeze if defined?(::Rails) unless @project_root raise "Please specify a project root in config/environments/test.rb using DiffTest.configure do |config| config.project_root = '/path/to/your/project' end " end @project_root end |
#run_on_main_branch=(value) ⇒ Object (writeonly)
Sets the attribute run_on_main_branch
3 4 5 |
# File 'lib/diff_test/configuration.rb', line 3 def run_on_main_branch=(value) @run_on_main_branch = value end |
#tracked_files ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/diff_test/configuration.rb', line 62 def tracked_files ||= begin @tracked_files ||= [ 'app/**/*.rb', 'app/**/*.html.erb', 'lib/**/*.rb', 'lib/**/*.html.erb', 'test/**/*.rb', '!test/fixtures/**/*', '!test/factories/**/*', '!test/factories.rb', ] filter_from_project_files(@tracked_files) end end |
#tracked_js_files ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/diff_test/configuration.rb', line 79 def tracked_js_files ||= begin @tracked_js_files ||= [ 'app/components/**/*.{js,jsx,ts,tsx,mjs,cjs,coffee}', 'app/javascript/**/*.{js,jsx,ts,tsx,mjs,cjs,coffee}', 'app/assets/javascripts/**/*.{js,jsx,ts,tsx,mjs,cjs,coffee}' ] filter_from_project_files(@tracked_js_files) end end |
#vendor_bundle_path ⇒ Object
39 40 41 42 43 |
# File 'lib/diff_test/configuration.rb', line 39 def vendor_bundle_path return @vendor_bundle_path.freeze if @vendor_bundle_path @vendor_bundle_path = File.join(project_root, 'vendor', 'bundle').to_s.freeze if defined?(::Rails) end |
Instance Method Details
#auto_annotate_js_files ⇒ Object
165 166 167 168 |
# File 'lib/diff_test/configuration.rb', line 165 def auto_annotate_js_files return :ci if @auto_annotate_js_files.nil? @auto_annotate_js_files end |
#auto_annotate_js_files=(value) ⇒ Object
170 171 172 |
# File 'lib/diff_test/configuration.rb', line 170 def auto_annotate_js_files=(value) @auto_annotate_js_files = value.nil? ? !!value : value end |
#auto_annotate_js_files? ⇒ Boolean
156 157 158 159 160 161 162 163 |
# File 'lib/diff_test/configuration.rb', line 156 def auto_annotate_js_files? case auto_annotate_js_files when :ci !!ci_platform else auto_annotate_js_files end end |
#ci_platform ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/diff_test/configuration.rb', line 102 def ci_platform if ENV['CIRCLECI'] 'circleci' elsif ENV['GITHUB_ACTIONS'] 'github-actions' elsif ENV['TRAVIS'] 'travis' elsif ENV['BUILDKITE'] 'buildkite' elsif ENV['JENKINS_URL'] 'jenkins' end end |
#enabled? ⇒ Boolean
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/diff_test/configuration.rb', line 133 def enabled? if !integratable? false elsif DiffTest::Helper.on_main_branch? && !run_on_main_branch? false elsif @enabled.respond_to?(:call) arity = @enabled.arity args = [] args << DiffTest::Helper.branch_name if arity >= 1 args << DiffTest::Helper.committer_email if arity >= 2 args << DiffTest::Helper.commit_title if arity >= 3 @enabled.call(*args) elsif @enabled.nil? true else @enabled end end |
#integratable? ⇒ Boolean
124 125 126 127 128 129 130 131 |
# File 'lib/diff_test/configuration.rb', line 124 def integratable? return false if ENV['DIFF_TEST_DISABLED'] == '1' return false if defined?(::Rails) && ::Rails.respond_to?(:env) && !::Rails.env.test? return false if DiffTest::Helper.on_skipped_branch? return false if DiffTest::Helper.on_skipped_commit? true end |
#port ⇒ Object
19 20 21 |
# File 'lib/diff_test/configuration.rb', line 19 def port @port || 8085 end |
#run_on_main_branch? ⇒ Boolean
152 153 154 |
# File 'lib/diff_test/configuration.rb', line 152 def run_on_main_branch? @run_on_main_branch.nil? ? true : @run_on_main_branch end |
#system_test_paths ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/diff_test/configuration.rb', line 91 def system_test_paths ||= begin @system_test_paths ||= [ 'test/system/**/*.rb', 'test/system/**/*.html.erb' ] filter_from_project_files(@system_test_paths) end end |