Class: PolishGeeks::DevTools::Commands::AllowedExtensions

Inherits:
Base
  • Object
show all
Defined in:
lib/polish_geeks/dev_tools/commands/allowed_extensions.rb

Overview

Checking config directory that all files are allowed

Constant Summary collapse

ALLOWED_EXTENSIONS =

List of allowed extensions of files

%w(
  rb
  yml
  rb.example
  yml.example
).freeze

Constants inherited from Base

Base::TYPES

Instance Attribute Summary

Attributes inherited from Base

#output, #stored_output

Instance Method Summary collapse

Methods inherited from Base

#ensure_executable!

Instance Method Details

#error_messageString

Returns error message that will be displayed if something goes wrong.

Returns:

  • (String)

    error message that will be displayed if something goes wrong



40
41
42
43
44
45
# File 'lib/polish_geeks/dev_tools/commands/allowed_extensions.rb', line 40

def error_message
  err = 'Following files are not allowed in config directory:'
  err << "\n\n"
  err << @output.join("\n")
  err << "\n"
end

#executeArray

Executes this command not allowed files in config directory

Returns:

  • (Array)

    command output array with list of



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/polish_geeks/dev_tools/commands/allowed_extensions.rb', line 19

def execute
  results = Dir[config_path]

  @output = results
            .flatten
            .map { |line| line.gsub!(PolishGeeks::DevTools.app_root + '/config/', '') }
            .uniq
  @output.delete_if do |line|
    ALLOWED_EXTENSIONS.any? { |allow| line =~ /^.*\.#{allow}$/i }
  end

  @output
end

#labelString

Returns label with this validator description.

Returns:

  • (String)

    label with this validator description



34
35
36
# File 'lib/polish_geeks/dev_tools/commands/allowed_extensions.rb', line 34

def label
  'Allowed Extensions'
end

#valid?Boolean

have correct extension

Returns:

  • (Boolean)

    true if all files in config directory



49
50
51
# File 'lib/polish_geeks/dev_tools/commands/allowed_extensions.rb', line 49

def valid?
  @output.empty?
end