Class: AUCoreTestKit::Generator::ReadTestGenerator
- Inherits:
-
Object
- Object
- AUCoreTestKit::Generator::ReadTestGenerator
- Defined in:
- lib/au_core_test_kit/generator/read_test_generator.rb
Instance Attribute Summary collapse
-
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
-
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #base_output_file_name ⇒ Object
- #class_name ⇒ Object
- #conformance_expectation ⇒ Object
- #generate ⇒ Object
-
#initialize(group_metadata, base_output_dir) ⇒ ReadTestGenerator
constructor
A new instance of ReadTestGenerator.
- #module_name ⇒ Object
- #needs_healthcare_service_id? ⇒ Boolean
- #needs_location_id? ⇒ Boolean
- #needs_organization_id? ⇒ Boolean
- #needs_practitioner_id? ⇒ Boolean
- #needs_practitioner_role_id? ⇒ Boolean
- #output ⇒ Object
- #output_file_directory ⇒ Object
- #output_file_name ⇒ Object
- #profile_identifier ⇒ Object
- #read_interaction ⇒ Object
- #resource_collection_string ⇒ Object
- #resource_type ⇒ Object
- #template ⇒ Object
- #test_id ⇒ Object
Constructor Details
#initialize(group_metadata, base_output_dir) ⇒ ReadTestGenerator
Returns a new instance of ReadTestGenerator.
24 25 26 27 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 24 def initialize(, base_output_dir) self. = self.base_output_dir = base_output_dir end |
Instance Attribute Details
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
22 23 24 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 22 def base_output_dir @base_output_dir end |
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
22 23 24 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 22 def @group_metadata end |
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 10 def generate(, base_output_dir) .groups .reject { |group| SpecialCases.exclude_group? group } .select { |group| read_interaction(group).present? } .each { |group| new(group, base_output_dir).generate } end |
.read_interaction(group_metadata) ⇒ Object
17 18 19 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 17 def read_interaction() .interactions.find { |interaction| interaction[:code] == 'read' } end |
Instance Method Details
#base_output_file_name ⇒ Object
37 38 39 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 37 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
61 62 63 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 61 def class_name "#{Naming.upper_camel_case_for_profile()}ReadTest" end |
#conformance_expectation ⇒ Object
81 82 83 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 81 def conformance_expectation read_interaction[:expectation] end |
#generate ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 105 def generate FileUtils.mkdir_p(output_file_directory) File.open(output_file_name, 'w') { |f| f.write(output) } .add_test( id: test_id, file_name: base_output_file_name ) end |
#module_name ⇒ Object
65 66 67 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 65 def module_name "AUCore#{.reformatted_version.upcase}" end |
#needs_healthcare_service_id? ⇒ Boolean
101 102 103 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 101 def needs_healthcare_service_id? resource_type == 'HealthcareService' end |
#needs_location_id? ⇒ Boolean
85 86 87 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 85 def needs_location_id? resource_type == 'Location' end |
#needs_organization_id? ⇒ Boolean
89 90 91 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 89 def needs_organization_id? resource_type == 'Organization' end |
#needs_practitioner_id? ⇒ Boolean
93 94 95 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 93 def needs_practitioner_id? resource_type == 'Practitioner' end |
#needs_practitioner_role_id? ⇒ Boolean
97 98 99 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 97 def needs_practitioner_role_id? resource_type == 'PractitionerRole' end |
#output ⇒ Object
33 34 35 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 33 def output @output ||= ERB.new(template).result(binding) end |
#output_file_directory ⇒ Object
41 42 43 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 41 def output_file_directory File.join(base_output_dir, profile_identifier) end |
#output_file_name ⇒ Object
45 46 47 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 45 def output_file_name File.join(output_file_directory, base_output_file_name) end |
#profile_identifier ⇒ Object
53 54 55 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 53 def profile_identifier Naming.snake_case_for_profile() end |
#read_interaction ⇒ Object
49 50 51 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 49 def read_interaction self.class.read_interaction() end |
#resource_collection_string ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 73 def resource_collection_string if .delayed? && resource_type != 'Provenance' "scratch.dig(:references, '#{resource_type}')" else 'all_scratch_resources' end end |
#resource_type ⇒ Object
69 70 71 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 69 def resource_type .resource end |
#template ⇒ Object
29 30 31 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 29 def template @template ||= File.read(File.join(__dir__, 'templates', 'read.rb.erb')) end |
#test_id ⇒ Object
57 58 59 |
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 57 def test_id "au_core_#{.reformatted_version}_#{profile_identifier}_read_test" end |