Class: ProjectConfiguration
- Inherits:
-
Object
- Object
- ProjectConfiguration
- Defined in:
- lib/almirah/project_configuration.rb
Instance Attribute Summary collapse
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#project_root_directory ⇒ Object
Returns the value of attribute project_root_directory.
Instance Method Summary collapse
- #get_design_inputs ⇒ Object
- #get_repositories ⇒ Object
-
#get_risk_columns(folder) ⇒ Object
The ordered register-column list for a risk registry folder (ADR-216), read from the risks: root — a list of { folder:, columns: } entries.
-
#get_risk_rpn_groups(folder) ⇒ Object
The named RPN groups of a risk registry folder (ADR-217), from the rpn: list of its risks: entry, in configured order: [{ name:, inputs: [..], acceptable:, unacceptable: }, ...].
-
#initialize(path) ⇒ ProjectConfiguration
constructor
A new instance of ProjectConfiguration.
- #is_spec_db_shall_be_created ⇒ Object
- #load_project_file ⇒ Object
- #numeric_threshold(value) ⇒ Object
-
#risk_entry(folder) ⇒ Object
The risks: entry configuring a registry folder, or nil when absent.
- #risk_rpn_group(raw) ⇒ Object
Constructor Details
#initialize(path) ⇒ ProjectConfiguration
Returns a new instance of ProjectConfiguration.
6 7 8 9 10 |
# File 'lib/almirah/project_configuration.rb', line 6 def initialize(path) @project_root_directory = File.(path) @parameters = {} load_project_file end |
Instance Attribute Details
#parameters ⇒ Object
Returns the value of attribute parameters.
4 5 6 |
# File 'lib/almirah/project_configuration.rb', line 4 def parameters @parameters end |
#project_root_directory ⇒ Object
Returns the value of attribute project_root_directory.
4 5 6 |
# File 'lib/almirah/project_configuration.rb', line 4 def project_root_directory @project_root_directory end |
Instance Method Details
#get_design_inputs ⇒ Object
20 21 22 23 24 |
# File 'lib/almirah/project_configuration.rb', line 20 def get_design_inputs return @parameters['specifications']['input'] if (@parameters.key? 'specifications') and (@parameters['specifications'].key? 'input') [] end |
#get_repositories ⇒ Object
26 27 28 29 30 |
# File 'lib/almirah/project_configuration.rb', line 26 def get_repositories return @parameters['repositories'] if @parameters.key? 'repositories' [] end |
#get_risk_columns(folder) ⇒ Object
The ordered register-column list for a risk registry folder (ADR-216), read from the risks: root — a list of { folder:, columns: } entries. nil when the registry carries no configuration; such a registry renders the implicit columns plus Status only.
36 37 38 39 40 41 |
# File 'lib/almirah/project_configuration.rb', line 36 def get_risk_columns(folder) entry = risk_entry(folder) return nil unless entry.is_a?(Hash) && entry['columns'].is_a?(Array) entry['columns'].map(&:to_s) end |
#get_risk_rpn_groups(folder) ⇒ Object
The named RPN groups of a risk registry folder (ADR-217), from the rpn: list of its risks: entry, in configured order: [{ name:, inputs: [..], acceptable:, unacceptable: }, ...]. Groups without a name or a non-empty inputs list are dropped; a threshold bound that is absent or not numeric is nil. Empty when the registry declares no groups.
48 49 50 51 52 53 |
# File 'lib/almirah/project_configuration.rb', line 48 def get_risk_rpn_groups(folder) entry = risk_entry(folder) return [] unless entry.is_a?(Hash) && entry['rpn'].is_a?(Array) entry['rpn'].filter_map { |raw| risk_rpn_group(raw) } end |
#is_spec_db_shall_be_created ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/almirah/project_configuration.rb', line 55 def is_spec_db_shall_be_created if @parameters.key? 'output' @parameters['output'].each do |p| return true if p == 'specifications_db' end end false end |
#load_project_file ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/almirah/project_configuration.rb', line 12 def load_project_file @parameters = YAML.load_file(@project_root_directory + '/project.yml') rescue Psych::SyntaxError => e puts "YAML syntax error: #{e.}" rescue Errno::ENOENT puts 'Project file not found: project.yml' end |
#numeric_threshold(value) ⇒ Object
87 88 89 |
# File 'lib/almirah/project_configuration.rb', line 87 def numeric_threshold(value) value.is_a?(Numeric) ? value : nil end |
#risk_entry(folder) ⇒ Object
The risks: entry configuring a registry folder, or nil when absent.
65 66 67 68 69 70 71 72 |
# File 'lib/almirah/project_configuration.rb', line 65 def risk_entry(folder) return nil unless @parameters.is_a?(Hash) entries = @parameters['risks'] return nil unless entries.is_a?(Array) entries.find { |e| e.is_a?(Hash) && e['folder'].to_s == folder } end |
#risk_rpn_group(raw) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/almirah/project_configuration.rb', line 74 def risk_rpn_group(raw) return nil unless raw.is_a?(Hash) name = raw['name'].to_s inputs = raw['inputs'] return nil if name.empty? || !inputs.is_a?(Array) || inputs.empty? thresholds = raw['thresholds'].is_a?(Hash) ? raw['thresholds'] : {} { name: name, inputs: inputs.map(&:to_s), acceptable: numeric_threshold(thresholds['acceptable']), unacceptable: numeric_threshold(thresholds['unacceptable']) } end |