class Toolbus
Constants
- SCAN_TIME_SECONDS
Public Class Methods
new()
click to toggle source
# File lib/toolbus.rb, line 11 def initialize validate_repo @features = fetch_features end
Public Instance Methods
fetch_features()
click to toggle source
# 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()
click to toggle source
# 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}, filename: #{file}, first_line: #{match[:first_line]}, last_line: #{match[:last_line]}, commit: #{head_sha}" 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()
click to toggle source
# 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
Private Instance Methods
feature_module_and_name(feature)
click to toggle source
# File lib/toolbus.rb, line 78 def feature_module_and_name(feature) [feature['module'], ': ', feature['name']].join end
features_found()
click to toggle source
# File lib/toolbus.rb, line 82 def features_found Hash[@features.map { |feature| [feature_module_and_name(feature), feature['count']] }] end
num_completions()
click to toggle source
# File lib/toolbus.rb, line 86 def num_completions @features.inject(0) { |total, feature| total + feature['count'] } end
num_features_completed()
click to toggle source
# File lib/toolbus.rb, line 90 def num_features_completed @features.select { |feature| feature['count'] > 0 }.count end
scanning_plan()
click to toggle source
# File lib/toolbus.rb, line 67 def scanning_plan hash_with_array_values = Hash.new { |h, k| h[k] = [] } @features.inject(hash_with_array_values) do |plan, feature| Dir.glob(feature['search_in']).each do |file| plan[file] << { feature['id'] => feature['search_for'] } end plan end end