Class: ProfileLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/cfn-nag/profile_loader.rb

Overview

Load rule profile

Instance Method Summary collapse

Constructor Details

#initialize(rules_registry) ⇒ ProfileLoader

Returns a new instance of ProfileLoader.



5
6
7
# File 'lib/cfn-nag/profile_loader.rb', line 5

def initialize(rules_registry)
  @rules_registry = rules_registry
end

Instance Method Details

#load(profile_definition:) ⇒ Object

Load rules from a profile definition



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cfn-nag/profile_loader.rb', line 10

def load(profile_definition:)
  # coerce falsy profile_definition into empty string for
  # empty profile check
  profile_definition ||= ''
  raise 'Empty profile' if profile_definition.strip == ''

  new_profile = Profile.new

  profile_definition.each_line do |line|
    next unless (rule_id = rule_line_match(line))
    check_valid_rule_id rule_id
    new_profile.add_rule rule_id
  end
  new_profile
end