Class: DaVinciPlanNetTestKit::Generator::ReferenceResolutionTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, base_output_dir) ⇒ ReferenceResolutionTestGenerator

Returns a new instance of ReferenceResolutionTestGenerator.



17
18
19
20
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 17

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.



15
16
17
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 15

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



15
16
17
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 15

def 
  @group_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



8
9
10
11
12
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 8

def generate(, base_output_dir)
  .groups
    .reject { |group| SpecialCases.exclude_group? group }
    .each { |group| new(group, base_output_dir).generate }
end

Instance Method Details

#base_output_file_nameObject



30
31
32
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 30

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

#class_nameObject



50
51
52
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 50

def class_name
  "#{Naming.upper_camel_case_for_profile()}ReferenceResolutionTest"
end

#generateObject



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 79

def generate
  return if must_support_references.empty?

  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_nameObject



54
55
56
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 54

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

#must_support_reference_list_stringObject



71
72
73
74
75
76
77
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 71

def must_support_reference_list_string
  must_support_references
    .map { |element| "#{' ' * 8}* #{resource_type}.#{element[:path]}" }
    .uniq
    .sort
    .join("\n")
end

#must_support_referencesObject



66
67
68
69
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 66

def must_support_references
  .must_supports[:elements]
    .select { |element| element[:types]&.include?('Reference') }
end

#outputObject



26
27
28
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 26

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

#output_file_directoryObject



34
35
36
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 34

def output_file_directory
  File.join(base_output_dir, profile_identifier)
end

#output_file_nameObject



38
39
40
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 38

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#profile_identifierObject



42
43
44
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 42

def profile_identifier
  Naming.snake_case_for_profile()
end

#resource_collection_stringObject



62
63
64
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 62

def resource_collection_string
  'scratch_resources[:all]'
end

#resource_typeObject



58
59
60
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 58

def resource_type
  .resource
end

#templateObject



22
23
24
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 22

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

#test_idObject



46
47
48
# File 'lib/davinci_plan_net_test_kit/generator/reference_resolution_test_generator.rb', line 46

def test_id
  "davinci_plan_net_#{.reformatted_version}_#{profile_identifier}_reference_resolution_test"
end