Skip to content

Commit

Permalink
Switch to using Flay as library directly rather than shelling out
Browse files Browse the repository at this point in the history
  • Loading branch information
etagwerker committed Nov 6, 2021
1 parent d491690 commit 7491449
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/metric_fu/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ def default_run_args
run_options.map { |k, v| "--#{k} #{v}" }.join(" ")
end

def run
def run(options = run_options)
not_implemented
end

# TODO: move into generator
def run_external(args = default_run_args)
runner = GemRun.new(
gem_name: gem_name.to_s,
Expand Down
19 changes: 14 additions & 5 deletions lib/metric_fu/metrics/flay/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ def self.metric
end

def emit
args = "#{minimum_duplication_mass} #{dirs_to_flay}"
@output = run!(args)
@output = run(options)
end

def analyze
Expand Down Expand Up @@ -35,17 +34,27 @@ def calculate_result(matches)
}
end

def run(options)
flay_options = Flay.default_options.merge(minimum_duplication_mass)
flay = Flay.new flay_options
files = Flay.expand_dirs_to_files(dirs_to_flay)
flay.process(*files)
MetricFu::Utility.capture_output do
flay.report
end
end

private

def minimum_duplication_mass
flay_mass = options[:minimum_score]
return "" unless flay_mass
return {} unless flay_mass

"--mass #{flay_mass} "
{ :mass => flay_mass }
end

def dirs_to_flay
options[:dirs_to_flay].join(" ")
options[:dirs_to_flay]
end
end
end
1 change: 1 addition & 0 deletions lib/metric_fu/metrics/flay/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def enable
end

def activate
activate_library 'flay'
super
end
end
Expand Down
9 changes: 7 additions & 2 deletions spec/metric_fu/metrics/flay/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
allow(File).to receive(:directory?).and_return(true)
@flay = MetricFu::FlayGenerator.new(options)

expect(@flay).to receive(:run!).with(" app lib")
expected_options = Flay.default_options
expect(Flay).to receive(:expand_dirs_to_files).with(options[:dirs_to_flay])
flay = double('flay', :process => nil)
allow(Flay).to receive(:new).and_return(flay)
output = @flay.emit
end

Expand All @@ -17,7 +20,9 @@
allow(File).to receive(:directory?).and_return(true)
@flay = MetricFu::FlayGenerator.new(options)

expect(@flay).to receive(:run!).with("--mass 99 ")
expected_options = Flay.default_options.merge(:mass => 99)
flay = double('flay', :process => nil)
expect(Flay).to receive(:new).with(expected_options).and_return(flay)
output = @flay.emit
end
end
Expand Down

0 comments on commit 7491449

Please sign in to comment.