Class: CreateRailsApp::Options::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/create_rails_app/options/validator.rb

Overview

Validates user-selected options against the compatibility entry for the detected Rails version.

Checks that: the app name is valid, every option key is known, every option is supported by this Rails version, and every value is valid for the option’s type and allowed values.

Constant Summary collapse

APP_NAME_PATTERN =

Returns pattern for valid Rails app names.

Returns:

  • pattern for valid Rails app names

/\A[a-zA-Z][a-zA-Z0-9_-]*\z/

Instance Method Summary collapse

Constructor Details

#initialize(compatibility_entry) ⇒ Validator

Returns a new instance of Validator.

Parameters:



16
17
18
# File 'lib/create_rails_app/options/validator.rb', line 16

def initialize(compatibility_entry)
  @compatibility_entry = compatibility_entry
end

Instance Method Details

#validate!(app_name:, options:) ⇒ true

Validates the app name and all options.

Parameters:

Returns:

Raises:

  • if any validation fails



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/create_rails_app/options/validator.rb', line 26

def validate!(app_name:, options:) # rubocop:disable Naming/PredicateMethod
  validate_app_name!(app_name)

  options.each do |key, value|
    validate_option_key!(key)
    validate_supported_option!(key)
    validate_value!(key, value)
    validate_supported_value!(key, value)
  end

  true
end