Class: CreateGithubRelease::CommandLine::Validator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/create_github_release/command_line/validator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Validates a set of options after the options have been fully initialized

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Validator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new instance of this class

Parameters:



13
14
15
# File 'lib/create_github_release/command_line/validator.rb', line 13

def initialize(options)
  @options = options
end

Instance Method Details

#errorsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an array of error messages

  • If the options are valid, returns an empty array
  • If the options are not valid, returns an array of error messages

Examples:

when all options are valid

options = CreateGithubRelease::CommandLine::Options.new
options.release_type = 'major'
options.valid? #=> true
options.errors #=> []

when one or more options are not valid

options = CreateGithubRelease::CommandLine::Options.new
options.release_type #=> nil
options.quiet = options.verbose = true
options.valid? #=> false
options.errors #=>  [
  "Both --quiet and --verbose cannot be given",
  "--release-type must be given and be one of 'major', 'minor', 'patch'"
]

Returns:

  • (Array<String>)

    an array of error messages



68
69
70
71
# File 'lib/create_github_release/command_line/validator.rb', line 68

def errors
  valid?
  @errors
end

#valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if all options are valid and false otherwise

  • If the options are valid, returns true clears the #errors array
  • If the options are not valid, returns false and populates the #errors array

Examples:

when all options are valid

options = CreateGithubRelease::CommandLine::Options.new
options.release_type = 'major'
options.valid? #=> true
options.errors #=> []

when one or more options are not valid

options = CreateGithubRelease::CommandLine::Options.new
options.release_type #=> nil
options.valid? #=> false
options.errors #=> ["--release-type must be given and be one of 'major', 'minor', 'patch'"]

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/create_github_release/command_line/validator.rb', line 36

def valid?
  @errors = []
  validation_classes.each do |validation_class|
    validation = validation_class.new(options)
    @errors << validation.error unless validation.valid?
  end
  @errors.empty?
end