Sha256: edca1d8bd5ffdb8c09e9099645de9c5da6ae049ffe9a2c1f7eace36d61b64c26

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module USCoreTestKit
  class Generator
    class ResourceListGenerator
      class << self
        def generate(ig_metadata)
          @ig_metadata = ig_metadata

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

        def resource_list
          @ig_metadata.groups.map(&:resource).uniq
        end

        def resource_list_string
          resource_list.map { |resource| "      '#{resource}'" }.join(",\n")
        end

        def read_interaction(group_metadata)
          group_metadata.interactions.find { |interaction| interaction[:code] == 'read' }
        end

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

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

        def base_output_file_name
          "resource_list.rb"
        end

        def output_file_directory
          File.join(__dir__, '..', 'generated')
        end

        def output_file_name
          File.join(output_file_directory, base_output_file_name)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
us_core_test_kit-0.1.1 lib/us_core_test_kit/generator/resource_list_generator.rb
us_core_test_kit-0.1.0 lib/us_core_test_kit/generator/resource_list_generator.rb