Class: USCoreTestKit::Generator::GranularScopeGroupGenerator
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::GranularScopeGroupGenerator
- Defined in:
- lib/us_core_test_kit/generator/granular_scope_group_generator.rb
Instance Attribute Summary collapse
-
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
-
#group_number ⇒ Object
Returns the value of attribute group_number.
-
#ig_metadata ⇒ Object
Returns the value of attribute ig_metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #base_metadata_file_name ⇒ Object
- #base_output_file_name ⇒ Object
- #class_name ⇒ Object
- #description ⇒ Object
- #generate ⇒ Object
- #group_dir ⇒ Object
- #group_file_list ⇒ Object
- #group_id ⇒ Object
- #group_id_list ⇒ Object
-
#initialize(ig_metadata, base_output_dir, group_number) ⇒ GranularScopeGroupGenerator
constructor
A new instance of GranularScopeGroupGenerator.
- #module_name ⇒ Object
- #output ⇒ Object
- #output_file_name ⇒ Object
- #scopes_string ⇒ Object
- #search_param_name_string ⇒ Object
- #short_description ⇒ Object
- #template ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(ig_metadata, base_output_dir, group_number) ⇒ GranularScopeGroupGenerator
Returns a new instance of GranularScopeGroupGenerator.
19 20 21 22 23 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 19 def initialize(, base_output_dir, group_number) self. = self.base_output_dir = base_output_dir self.group_number = group_number end |
Instance Attribute Details
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
17 18 19 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 17 def base_output_dir @base_output_dir end |
#group_number ⇒ Object
Returns the value of attribute group_number.
17 18 19 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 17 def group_number @group_number end |
#ig_metadata ⇒ Object
Returns the value of attribute ig_metadata.
17 18 19 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 17 def @ig_metadata end |
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 8 def generate(, base_output_dir) return unless ['6', '7'].include? .ig_version[1] [1, 2].each do |group_number| new(, base_output_dir, group_number).generate end end |
Instance Method Details
#base_metadata_file_name ⇒ Object
37 38 39 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 37 def "metadata.yml" end |
#base_output_file_name ⇒ Object
33 34 35 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 33 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
41 42 43 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 41 def class_name "GranularScopes#{group_number}Group" end |
#description ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 116 def description <<~DESCRIPTION The tests in this group repeat all of the searches from the US Core FHIR API tests, and verify that the resources returned are filtered based on the following granular scopes: #{scopes_string} DESCRIPTION end |
#generate ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 69 def generate FileUtils.mkdir_p(group_dir) File.open(output_file_name, 'w') { |f| f.write(output) } .granular_scope_groups << { id: group_id, file_name: base_output_file_name } end |
#group_dir ⇒ Object
61 62 63 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 61 def group_dir File.join(base_output_dir, 'granular_scope_tests') end |
#group_file_list ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 89 def group_file_list @group_file_list ||= .granular_scope_resource_type_groups .values .flatten .select { |group| group[:file_name].include? "scope#{group_number}" } .map do |group| name_without_suffix = group[:file_name].delete_suffix('.rb') "./#{name_without_suffix}" end end |
#group_id ⇒ Object
65 66 67 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 65 def group_id "us_core_#{.reformatted_version}_smart_granular_scopes_#{group_number}" end |
#group_id_list ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 79 def group_id_list @group_id_list ||= .granular_scope_resource_type_groups .values .flatten .map { |group| group[:id] } .select { |id| id.include? "scope_#{group_number}" } end |
#module_name ⇒ Object
45 46 47 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 45 def module_name "USCore#{.reformatted_version.upcase}" end |
#output ⇒ Object
29 30 31 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 29 def output @output ||= ERB.new(template).result(binding) end |
#output_file_name ⇒ Object
57 58 59 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 57 def output_file_name File.join(base_output_dir, base_output_file_name) end |
#scopes_string ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 108 def scopes_string SmartScopesConstants.const_get("SMART_GRANULAR_SCOPES_GROUP#{group_number}") .dig(.reformatted_version) .map { |scope| scope.delete_prefix 'patient/' } .map { |scope| "* `#{scope}`" } .join("\n") end |
#search_param_name_string ⇒ Object
101 102 103 104 105 106 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 101 def search_param_name_string required_searches .map { |search| search[:names].join(' + ') } .map { |names| "* #{names}" } .join("\n") end |
#short_description ⇒ Object
53 54 55 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 53 def short_description # TODO end |
#template ⇒ Object
25 26 27 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 25 def template @template ||= File.read(File.join(__dir__, 'templates', 'granular_scope_group.rb.erb')) end |
#title ⇒ Object
49 50 51 |
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 49 def title "#US Core FHIR API w/Granular Scopes #{group_number}" end |