Class: Toolbus
Constant Summary collapse
- SCAN_TIME_SECONDS =
4.0
Instance Attribute Summary
Attributes included from GitUtils
Instance Method Summary collapse
- #fetch_features ⇒ Object
-
#initialize ⇒ Toolbus
constructor
A new instance of Toolbus.
- #scan ⇒ Object
- #validate_repo ⇒ Object
Methods included from GitUtils
#git_status_clean?, #latest_commit_online?
Constructor Details
#initialize ⇒ Toolbus
Returns a new instance of Toolbus.
11 12 13 14 |
# File 'lib/toolbus.rb', line 11 def initialize validate_repo @features = fetch_features end |
Instance Method Details
#fetch_features ⇒ Object
21 22 23 24 |
# File 'lib/toolbus.rb', line 21 def fetch_features # TODO: GET all features for our tools and versions, once that API exists JSON.parse(File.read(File.open(File.join(TOOLBUS_ROOT, 'spec/fixture/sample.json'))))['data'] end |
#scan ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/toolbus.rb', line 27 def scan statuses = [] progress = 0.0 @features.map { |feature| feature.default = 0 } # helps measure progress num_steps = scanning_plan.inject(0) { |total, (file, blueprints)| total + blueprints.length } scanning_plan.each_with_index do |(file, search_for), file_index| statuses << "Scanning #{file}" search_for.each do |search_for| id = search_for.keys.first blueprint = search_for.values.first progress += 1 begin match = SyntaxTree.new(file).include?(SyntaxTree.new(blueprint)) rescue Parser::SyntaxError statuses << "Syntax Error: #{file}" next end if match feature = @features.find { |feature| feature['id'] == id } feature['count'] += 1 statuses << "POST /completions: repo_url: #{repo_url}, feature_id: #{id}, commit: ???, filename: #{file}, first_line: #{match[:first_line]}, last_line: #{match[:last_line]}" end percent_complete = (progress / num_steps) * 100 ConsoleManager.repaint([ ProgressBarView.new(percent_complete), TableView.new(features_found), StatusBoxView.new(statuses), "Found #{num_completions} total completions across #{num_features_completed}/#{@features.count} features across #{file_index}/#{scanning_plan.count} files!" ]) sleep SCAN_TIME_SECONDS / num_steps end end end |
#validate_repo ⇒ Object
16 17 18 19 |
# File 'lib/toolbus.rb', line 16 def validate_repo ConsoleManager.error "Unpushed commits! Push or stash before running." unless latest_commit_online? ConsoleManager.error "Uncommitted changes! Stash or commit and push before running." unless git_status_clean? end |