ruby-flog-flay-setup
Ruby Flog Flay Setup
Overview
Install flog/flay Rake tasks with env-configurable thresholds and a pre-commit hook that runs bundle exec rake.
Workflow
1) Inspect existing setup
- Check
Gemfileforflogandflayentries. - Search for existing
:flogor:flayrake tasks inRakefileandrakelib/to avoid duplicates. - Check
git config core.hooksPathto determine the hooks directory (default is.git/hookswhen unset).
2) Ensure dependencies
- Add
gem "flay"andgem "flog"toGemfileif missing (no version pinning). - Run
bundle installif needed.
3) Define tasks in Rakefile
- Define
:flogand:flaytasks directly inRakefile. - Use env-configurable thresholds with defaults.
- Use
bundle execfor both tools. - Log only on failure using
putsand exit non-zero; stay silent on success. - Do not filter out any files or paths.
- Allow flay duplication when
Total score <= FLAY_THRESHOLD.
Example task definitions:
desc "Run flog"
task :flog do
output = `bundle exec flog -a lib`
threshold = (ENV["FLOG_THRESHOLD"] || 25).to_i
method_scores = []
output.each_line do |line|
if line =~ /^\s*(\d+\.\d+):\s+(.+#.+)\s+(.+\.rb)/
score = $1.to_f
method_name = $2.strip
file_path = $3.strip
method_scores << [score, "#{method_name} #{file_path}"]
end
end
failing_methods = method_scores.select { |score, _| score > threshold }
if failing_methods.any?
puts "\nFlog failed: Methods with complexity score > #{threshold}:"
failing_methods.each { |score, method_name| puts " #{score}: #{method_name}" }
exit 1
end
end
desc "Run flay"
task :flay do
output = `bundle exec flay lib`
threshold = (ENV["FLAY_THRESHOLD"] || 0).to_i
if (match = output.match(/Total score \(lower is better\) = (\d+)/))
score = match[1].to_i
if score > threshold
puts "\nFlay failed: Total duplication score is #{score}, must be <= #{threshold}"
puts output
exit 1
end
end
end
- Remove or update any conflicting
:flog/:flaytasks inrakelib/to avoid duplicate definitions. - Ensure the default task includes
flogandflayif the project expects them to run in CI.
4) Install pre-commit hook
- Create or update
pre-commitin the hooks directory fromcore.hooksPath(or.git/hooks). - Use bash and run
bundle exec rakeunconditionally. - Exit non-zero if rake fails.
Example hook:
#!/usr/bin/env bash
bundle exec rake
result=$?
if [ $result -ne 0 ]; then
echo "bundle exec rake failed. Commit aborted."
exit $result
fi
- Ensure the hook is executable.
5) Verify
- Run
bundle exec rakeand confirm it succeeds. - Make a test commit if needed to confirm the hook blocks failing builds.
More from nateberkopec/dotfiles
sandi-metz-rules
This skill should be used when users request code review, refactoring, or code quality improvements for Ruby codebases. Apply Sandi Metz's four rules for writing maintainable object-oriented code - classes under 100 lines, methods under 5 lines, no more than 4 parameters, and controllers instantiate only one object. Use when users mention "Sandi Metz", "code quality", "refactoring", or when reviewing Ruby code for maintainability.
15nanobanana
Generate, edit, and restore images using Gemini CLI with the Nano Banana extension. Use when users request image generation, edits, icons, patterns, diagrams, or visual storytelling.
15argument-validator
This skill should be used when users want to validate or critique an argument by extracting premises, surfacing hidden assumptions, checking logical validity, optionally formalizing in Lean, and researching premise support.
15webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
14env-to-fnox
This skill should be used when users want to migrate from .env files to fnox with 1Password (or another secret provider). It covers installing fnox, creating 1Password items, configuring fnox.toml, and integrating with mise. Use when users mention ".env migration", "fnox setup", "1password secrets", or want to improve their secret management workflow.
14deep-research
This skill should be used when users request comprehensive, in-depth research on a topic that requires detailed analysis similar to an academic journal or whitepaper. The skill conducts multi-phase research using web search and content analysis, employing high parallelism with multiple subagents, and produces a detailed markdown report with citations.
14