Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flay directly #231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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