Sha256: a1f380e895360a4cae6c0aed3c922652abc137d90e68bcd55f400508d5d0d5d0

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 KB

Contents

require_relative '../dsl'
require_relative '../repositories/test_groups'
require_relative '../repositories/test_sessions'

module Inferno
  module Entities
    class TestGroup
      extend Forwardable
      extend DSL::FHIRClient::ClassMethods
      extend DSL::HTTPClient::ClassMethods
      extend DSL::Runnable
      include DSL::FHIRValidation

      def_delegators 'self.class', :title, :id, :groups, :inputs, :outputs, :tests

      def method_missing(name, *args, &block)
        parent_instance = self.class.parent&.new
        if parent_instance.respond_to?(name)
          parent_instance.send(name, *args, &block)
        else
          super
        end
      end

      def respond_to_missing?(name, _include_private = false)
        self.class.parent&.new&.respond_to?(name)
      end

      class << self
        def repository
          Inferno::Repositories::TestGroups.new
        end

        def groups
          @groups ||= []
        end

        def tests
          @tests ||= []
        end

        # Methods to configure Inferno::DSL::Runnable

        def group(...)
          child_metadata(group_metadata)
          define_child(...)
        end

        def test(...)
          child_metadata(test_metadata)
          define_child(...)
        end

        def group_metadata
          {
            class: TestGroup,
            repo: repository,
            collection: groups
          }
        end

        def test_metadata
          {
            class: Test,
            repo: Inferno::Repositories::Tests.new,
            collection: tests
          }
        end

        def default_id
          return name if name.present?

          suffix = parent ? (parent.groups.find_index(self) + 1).to_s.rjust(2, '0') : SecureRandom.uuid
          "Group#{suffix}"
        end

        def reference_hash
          {
            test_group_id: id
          }
        end
      end
    end
  end

  TestGroup = Entities::TestGroup
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
inferno_core-0.0.5 lib/inferno/entities/test_group.rb
inferno_core-0.0.4 lib/inferno/entities/test_group.rb
inferno_core-0.0.3 lib/inferno/entities/test_group.rb
inferno_core-0.0.2 lib/inferno/entities/test_group.rb
inferno_core-0.0.1 lib/inferno/entities/test_group.rb