Class: Oscal::Catalog

Inherits:
Object
  • Object
show all
Includes:
CommonUtils, Serializer
Defined in:
lib/oscal/catalog.rb

Constant Summary collapse

KEY =
%i(uuid metadata params controls groups back_matter)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonUtils

#find_object_by_id, included

Methods included from Serializer

included, #to_h, #to_json, #to_xml, #to_yaml

Constructor Details

#initialize(uuid, metadata, params, controls, groups, back_matter) ⇒ Catalog



15
16
17
18
19
20
21
22
23
24
# File 'lib/oscal/catalog.rb', line 15

def initialize(uuid, , params, controls, groups, back_matter)
  @uuid        = uuid
  @metadata    = MetadataBlock.new()
  @params      = Parameter.wrap(params) if params
  @controls    = Control.wrap(controls) if controls
  @groups      = Group.wrap(groups) if groups
  @back_matter = BackMatter.wrap(back_matter) if back_matter

  @all_controls = []
end

Class Method Details

.load_from_yaml(path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/oscal/catalog.rb', line 26

def self.load_from_yaml(path)
  yaml_data     = safe_load_yaml(path)
  yaml_catalog  = yaml_data["catalog"]

  uuid          = yaml_catalog["uuid"]
        = yaml_catalog["metadata"]
  params        = yaml_catalog["params"]
  controls      = yaml_catalog["controls"]
  groups        = yaml_catalog["groups"]
  back_matter   = yaml_catalog["back-matter"]

  Catalog.new(uuid, , params, controls, groups, back_matter)
end

Instance Method Details

#append_all_control_group(obj) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/oscal/catalog.rb', line 45

def append_all_control_group(obj)
  if /Oscal::Control/.match?(obj.to_s)
    @all_controls << obj
  end

  if obj.respond_to?(:controls) && !obj.controls.nil?
    obj.controls.each do |c|
      append_all_control_group(c)
    end
  end

  if obj.respond_to?(:groups) && !obj.groups.nil?
    obj.groups.each do |g|
      append_all_control_group(g)
    end
  end
end

#get_all_controlsObject



40
41
42
43
# File 'lib/oscal/catalog.rb', line 40

def get_all_controls
  append_all_control_group(self)
  @all_controls.uniq
end