Module: Idxfence

Defined in:
lib/idxfence.rb,
lib/idxfence/cli.rb,
lib/idxfence/render.rb,
lib/idxfence/checker.rb,
lib/idxfence/finding.rb,
lib/idxfence/version.rb,
lib/idxfence/inflector.rb,
lib/idxfence/model_parser.rb,
lib/idxfence/schema_parser.rb

Defined Under Namespace

Modules: CLI, Inflector, Render Classes: Checker, Finding, ModelParser, SchemaParser

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.check(project_dir:) ⇒ Array(Array<Finding>, String, nil)

Scans a Rails project root for ActiveRecord uniqueness: true / uniqueness: { ... } / validates_uniqueness_of validations under app/models/**/*.rb with no matching unique index in db/schema.rb.

Parameters:

  • project_dir (String) —

    path to a Rails project root (the directory containing app/ and db/)

Returns:

  • (Array(Array<Finding>, String, nil)) —

    findings, and a warning string (nil if none) when db/schema.rb was missing or unparseable



21
22
23
24
25
26
# File 'lib/idxfence.rb', line 21

def check(project_dir:)
  model_paths = Dir.glob(File.join(project_dir, "app", "models", "**", "*.rb"))
  schema_path = File.join(project_dir, "db", "schema.rb")

  check_paths(model_paths: model_paths, schema_path: schema_path)
end

.check_paths(model_paths:, schema_path:) ⇒ Array(Array<Finding>, String, nil)

Lower-level entry point: an explicit list of model file paths and one schema.rb path, for callers that already know their own layout (or for testing against fixtures that aren't laid out as a full Rails project).

Parameters:

  • model_paths (Array<String>)
  • schema_path (String)

Returns:

  • (Array(Array<Finding>, String, nil))


36
37
38
# File 'lib/idxfence.rb', line 36

def check_paths(model_paths:, schema_path:)
  Checker.new(model_paths: model_paths, schema_path: schema_path).call
end