Class: Filterable::DeclarationsValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/filterable/declarations_validator.rb

Overview

Checks a model's declarations against its actual columns and scopes, so a typo in a declaration — a silent no-op at runtime by design — can be caught by a spec:

expect(MovementDetail.filterable_declarations).to be_valid

Never used by the engine at runtime: filtering stays a silent no-op on unknown attributes.

Constant Summary collapse

KINDS =

The column-backed declaration DSLs to check, each exposing <kind>_attribute_names on the model. A kind the model does not respond to is skipped.

%i[datable sortable equatable rangeable matchable].freeze
SCOPE_KINDS =

The scope-backed declaration DSLs to check, each exposing <kind>_scope_names on the model. A kind the model does not respond to is skipped.

%i[scopable togglable].freeze
ATTACHMENT_KINDS =

The attachment-backed declaration DSLs to check, each exposing <kind>_attachment_names on the model. A kind the model does not respond to is skipped.

%i[attachable].freeze

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ DeclarationsValidator

Builds a validator over one model's declarations.

Parameters:

  • model (Class)

    an ActiveRecord model using the declaration DSLs.

Instance Method Details

#errorsArray<String>

The declarations pointing to unknown columns or scopes, as human-readable messages.

Returns:

  • (Array<String>)

    one message per broken declaration; empty when valid.

#valid?Boolean

Whether every declaration maps onto an existing column or scope.

Returns:

  • (Boolean)