Class: USCoreTestKit::Generator::GranularScopeReadTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, base_output_dir) ⇒ GranularScopeReadTestGenerator

Returns a new instance of GranularScopeReadTestGenerator.



28
29
30
31
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 28

def initialize(, base_output_dir)
  self. = 
  self.base_output_dir = base_output_dir
end

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



26
27
28
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 26

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



26
27
28
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 26

def 
  @group_metadata
end

#group_numberObject

Returns the value of attribute group_number.



26
27
28
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 26

def group_number
  @group_number
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 9

def generate(, base_output_dir)
  return if .ig_version[1].to_i < 6

  scopes =
    SmartScopesConstants::SMART_GRANULAR_SCOPES_GROUP1[.reformatted_version] +
    (SmartScopesConstants::SMART_GRANULAR_SCOPES_GROUP2[.reformatted_version] || [])

  SmartScopesConstants::SMART_GRANULAR_SCOPE_RESOURCES.each do |resource_type|
    group = .groups.find { |group| group.resource == resource_type }

    next if scopes.none? { |scope| scope.start_with? "patient/#{group.resource}" }

  new(group, base_output_dir).generate
  end
end

Instance Method Details

#array_of_strings(array) ⇒ Object



77
78
79
80
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 77

def array_of_strings(array)
  quoted_strings = array.map { |element| "'#{element}'" }
  "[#{quoted_strings.join(', ')}]"
end

#base_output_file_nameObject



41
42
43
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 41

def base_output_file_name
  "#{class_name.underscore}.rb"
end

#class_nameObject



61
62
63
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 61

def class_name
  "#{resource_type}GranularScopeReadTest"
end

#descriptionObject



92
93
94
95
96
97
98
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 92

def description
  <<~DESCRIPTION.gsub(/\n{3,}/, "\n\n")
    This test attempts #{resource_type} reads
    and verifies that the results have been
    filtered based on the granted granular scopes.
  DESCRIPTION
end

#generateObject



82
83
84
85
86
87
88
89
90
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 82

def generate
  FileUtils.mkdir_p(output_file_directory)
  File.open(output_file_name, 'w') { |f| f.write(output) }

  .add_granular_scope_test(
    id: test_id,
    file_name: base_output_file_name
  )
end

#module_nameObject



65
66
67
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 65

def module_name
  "USCore#{.reformatted_version.upcase}"
end

#outputObject



37
38
39
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 37

def output
  @output ||= ERB.new(template).result(binding)
end

#output_file_directoryObject



45
46
47
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 45

def output_file_directory
  File.join(base_output_dir, 'granular_scope_tests', resource_type.underscore)
end

#output_file_nameObject



49
50
51
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 49

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#path_for_value(path) ⇒ Object



73
74
75
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 73

def path_for_value(path)
  path == 'class' ? 'local_class' : path
end

#profile_identifierObject



53
54
55
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 53

def profile_identifier
  Naming.snake_case_for_profile()
end

#resource_typeObject



69
70
71
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 69

def resource_type
  .resource
end

#templateObject



33
34
35
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 33

def template
  @template ||= File.read(File.join(__dir__, 'templates', 'granular_scope_read_test.rb.erb'))
end

#test_idObject



57
58
59
# File 'lib/us_core_test_kit/generator/granular_scope_read_test_generator.rb', line 57

def test_id
  "us_core_#{.reformatted_version}_#{resource_type}_granular_scope_read_test"
end