Class: PropertyGenerator::GlobalsLinter
- Inherits:
-
Object
- Object
- PropertyGenerator::GlobalsLinter
- Defined in:
- lib/linter/globals_linter.rb
Constant Summary collapse
- TESTS =
[ 'globals_load_as_hashes', 'globals_are_defined_for_valid_environemnts' ].freeze
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, ignored_tests) ⇒ GlobalsLinter
constructor
A new instance of GlobalsLinter.
- #run_globals_tests ⇒ Object
Constructor Details
#initialize(path, configs, ignored_tests) ⇒ GlobalsLinter
12 13 14 15 16 17 18 19 20 |
# File 'lib/linter/globals_linter.rb', line 12 def initialize(path, configs, ignored_tests) @configs = configs @globals = {} @ignored_tests = ignored_tests 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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/linter/globals_linter.rb', line 62 def globals_are_defined_for_valid_environemnts status = { status: 'pass', error: '' } ignore_list = ['globals.yml'] if @configs['accounts'].nil? status[:status] = 'warn' status[:error] = 'Accounts list in config file is missing.' return status end accounts = @configs['accounts'].map(&:to_s) globals_with_invalid_environments = @globals.keys.select do |path| p = Pathname.new(path) filename = p.basename(File.extname(path)).to_s next if ignore_list.include?(p.basename.to_s) !(@configs['environments'].include?(filename) || accounts.include?(filename)) end unless globals_with_invalid_environments.empty? status[:status] = 'warn' status[:error] = "Files #{globals_with_invalid_environments} do not have names matching a declared environment." end status end |
#globals_have_no_hashes_as_values ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/linter/globals_linter.rb', line 43 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/linter/globals_linter.rb', line 28 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
22 23 24 25 26 |
# File 'lib/linter/globals_linter.rb', line 22 def run_globals_tests tests = TESTS - @ignored_tests PropertyGenerator.test_runner(self, tests) end |