Class: ReactorSDK::Resources::LibrarySnapshotIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/reactor_sdk/resources/library_snapshot_index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules:, data_elements:, extensions:, rule_components_by_rule_id:) ⇒ LibrarySnapshotIndex

Returns a new instance of LibrarySnapshotIndex.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 8

def initialize(rules:, data_elements:, extensions:, rule_components_by_rule_id:)
  @rules = Array(rules)
  @data_elements = Array(data_elements)
  @extensions = Array(extensions)
  @rule_components_by_rule_id = normalize_rule_components(rule_components_by_rule_id)
  @rule_components = @rule_components_by_rule_id.values.flatten
  @resource_by_id = build_resource_index
  @data_elements_by_name = build_data_element_name_index
  @data_element_dependency_graph = build_data_element_dependency_graph
  @reverse_data_element_graph = invert_graph(@data_element_dependency_graph)
  @rule_dependency_graph = build_rule_dependency_graph
  @rules_by_data_element = invert_graph(@rule_dependency_graph)
  @extension_index = LibrarySnapshotExtensionIndex.new(
    data_elements: @data_elements,
    rule_components_by_rule_id: @rule_components_by_rule_id,
    find_resource: method(:find_resource),
    sort_rule_components: method(:sort_rule_components)
  )
end

Instance Attribute Details

#resource_by_idObject (readonly)

Returns the value of attribute resource_by_id.



6
7
8
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 6

def resource_by_id
  @resource_by_id
end

#rule_componentsObject (readonly)

Returns the value of attribute rule_components.



6
7
8
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 6

def rule_components
  @rule_components
end

#rule_components_by_rule_idObject (readonly)

Returns the value of attribute rule_components_by_rule_id.



6
7
8
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 6

def rule_components_by_rule_id
  @rule_components_by_rule_id
end

Instance Method Details

#data_elements_for_extension(extension_or_id) ⇒ Object



46
47
48
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 46

def data_elements_for_extension(extension_or_id)
  @extension_index.data_elements_for(extract_id(extension_or_id))
end

#find_resource(resource_id) ⇒ Object



28
29
30
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 28

def find_resource(resource_id)
  @resource_by_id[extract_id(resource_id)]
end

#impacted_rules_for(data_element_or_id) ⇒ Object



40
41
42
43
44
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 40

def impacted_rules_for(data_element_or_id)
  impacted_rule_ids_for(data_element_or_id)
    .filter_map { |resource_id| find_resource(resource_id) }
    .sort_by { |rule| [rule.name.to_s, rule.id] }
end

#referenced_data_elements_for(data_element_or_id) ⇒ Object



36
37
38
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 36

def referenced_data_elements_for(data_element_or_id)
  referenced_resource_ids(data_element_or_id).filter_map { |resource_id| find_resource(resource_id) }
end

#rule_components_for_extension(extension_or_id) ⇒ Object



50
51
52
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 50

def rule_components_for_extension(extension_or_id)
  @extension_index.rule_components_for(extract_id(extension_or_id))
end

#rule_components_for_rule(rule_or_id) ⇒ Object



32
33
34
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 32

def rule_components_for_rule(rule_or_id)
  @rule_components_by_rule_id.fetch(extract_id(rule_or_id), [])
end

#rules_for_extension(extension_or_id) ⇒ Object



54
55
56
# File 'lib/reactor_sdk/resources/library_snapshot_index.rb', line 54

def rules_for_extension(extension_or_id)
  @extension_index.rules_for(extract_id(extension_or_id))
end