Class: Filterameter::DeclarationsValidator

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/filterameter/declarations_validator.rb

Overview

Declarations Validator

Class DeclarationsValidtor fetches each filter and sort from the registry to validate the declaration. This class can be accessed from the controller as declarations_validator (via the FilterCoordinator) and be used in tests.

Use the valid? method to test, then report errors with the errors attribute.

A test in RSpec might look like this:

expect(WidgetsController.declarations_validator).to be_valid

In Minitest it might look like this:

assert WidgetsController.declarations_validator.valid?, WidgetsController.declarations_validator.errors

Defined Under Namespace

Classes: FactoryErrors

Instance Method Summary collapse

Methods included from Errors

#valid?

Constructor Details

#initialize(controller_name, model, registry) ⇒ DeclarationsValidator

Returns a new instance of DeclarationsValidator.



21
22
23
24
25
# File 'lib/filterameter/declarations_validator.rb', line 21

def initialize(controller_name, model, registry)
  @controller_name = controller_name
  @model = model
  @registry = registry
end

Instance Method Details

#errorsObject



31
32
33
# File 'lib/filterameter/declarations_validator.rb', line 31

def errors
  @errors&.join("\n")
end

#inspectObject



27
28
29
# File 'lib/filterameter/declarations_validator.rb', line 27

def inspect
  "filter declarations on #{@controller_name.titleize}Controller"
end