Class: PolishGeeks::DevTools::Commands::ExpiresIn

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

Overview

Checking Rails cache options especially expires_in

Constant Summary collapse

CHECKED_DIRS =

List of dirs that we will check for

%w(
  app
  lib
).freeze
CHECKED_REGEXP =

Regexp that we want to use to catch invalid things that occur instead of expires_in

'expire_in\|expir_in'.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.

Returns:

  • (String)

    error message



42
43
44
45
46
47
# File 'lib/polish_geeks/dev_tools/commands/expires_in.rb', line 42

def error_message
  err = 'Following files use expire_in instead of expires_in:'
  err << "\n\n"
  err << @output.join("\n")
  err << "\n"
end

#excludesArray<String>

Note:

This should be set in the initializer for this gem in the place where it is going to be used

Returns list of files/directories that should be excluded from checking.

Returns:

  • (Array<String>)

    list of files/directories that should be excluded from checking



57
58
59
# File 'lib/polish_geeks/dev_tools/commands/expires_in.rb', line 57

def excludes
  DevTools.config.expires_in_files_ignored || []
end

#executeObject

Executes this command



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

def execute
  results = CHECKED_DIRS.map do |directory|
    path = File.join(PolishGeeks::DevTools.app_root, directory)
    shell_command(path).split("\n")
  end

  @output = results
            .flatten
            .map { |line| line.split(':').first }
            .map { |line| line.gsub!(PolishGeeks::DevTools.app_root, '') }
            .uniq

  @output.delete_if do |line|
    excludes.any? { |exclude| line =~ /#{exclude}/ }
  end
end

#labelString

Returns label with this validator description.

Returns:

  • (String)

    label with this validator description



37
38
39
# File 'lib/polish_geeks/dev_tools/commands/expires_in.rb', line 37

def label
  'Expires in'
end

#valid?Boolean

Returns true if not find expire_in.

Returns:

  • (Boolean)

    true if not find expire_in



50
51
52
# File 'lib/polish_geeks/dev_tools/commands/expires_in.rb', line 50

def valid?
  @output.empty?
end