Class: PropertyGenerator::GlobalsLinter
- Inherits:
-
Object
- Object
- PropertyGenerator::GlobalsLinter
- Defined in:
- lib/linter/globals_linter.rb
Instance Method Summary collapse
- #globals_are_defined_for_valid_environemnts ⇒ Object
- #globals_have_no_hashes_as_values ⇒ Object
- #globals_load_as_hashes ⇒ Object
-
#initialize(path, configs) ⇒ GlobalsLinter
constructor
A new instance of GlobalsLinter.
- #run_globals_tests ⇒ Object
Constructor Details
#initialize(path, configs) ⇒ GlobalsLinter
Returns a new instance of GlobalsLinter.
5 6 7 8 9 10 11 12 |
# File 'lib/linter/globals_linter.rb', line 5 def initialize(path, configs) @configs = configs @globals = {} valid_paths = PropertyGenerator.valid_paths(path) valid_paths.each do |file_path| @globals[file_path] = YAML.load_file(file_path) end end |
Instance Method Details
#globals_are_defined_for_valid_environemnts ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/linter/globals_linter.rb', line 57 def globals_are_defined_for_valid_environemnts status = {status: 'pass', error: ''} ignore_list = ['globals.yml'] globals_with_invalid_environments = [] accounts = [] if @configs['accounts'] != nil @configs['accounts'].each do |account| accounts << account.to_s end @globals.each do |path, loaded| unless @configs['environments'].include?((path.split('/')[(path.split('/')).length - 1]).split('.')[0]) || accounts.include?((path.split('/')[(path.split('/')).length - 1]).split('.')[0]) globals_with_invalid_environments << path unless ignore_list.include?(path.split('/')[(path.split('/')).length - 1]) end end if globals_with_invalid_environments != [] status[:status] = 'warn' status[:error] = "Files #{globals_with_invalid_environments} do not have names matching a declared environment." end else status[:status] = 'warn' status[:error] = "Accounts list in config file is missing." end status end |
#globals_have_no_hashes_as_values ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/linter/globals_linter.rb', line 38 def globals_have_no_hashes_as_values status = {status: 'pass', error: ''} globals_with_hash_props = [] @globals.each do |path, loaded| if loaded.class == Hash loaded.each do |key, value| if value.class == Hash globals_with_hash_props << {path => key} end end end end if globals_with_hash_props != [] status[:status] = 'fail' status[:error] = "Globals #{globals_with_hash_props} have values that are hashes." end status end |
#globals_load_as_hashes ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/linter/globals_linter.rb', line 23 def globals_load_as_hashes status = {status: 'pass', error: ''} non_hash_globals = [] @globals.each do |path, loaded| if loaded.class != Hash non_hash_globals << path end end if non_hash_globals != [] status[:status] = 'fail' status[:error] = "Global files #{non_hash_globals} are not being loaded as hashes." end status end |
#run_globals_tests ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/linter/globals_linter.rb', line 14 def run_globals_tests tests = ['globals_load_as_hashes', 'globals_have_no_hashes_as_values', 'globals_are_defined_for_valid_environemnts', ] results = PropertyGenerator.test_runner(self, tests) results end |