Sha256: 51e051335a1c2ec6b092c12865183cbfacaefe75dda63cbe5d46553f07ca2cb8

Contents?: true

Size: 1005 Bytes

Versions: 4

Compression:

Stored size: 1005 Bytes

Contents

require 'erb'

require_relative 'in_memory_repository'
require_relative '../entities/preset'

module Inferno
  module Repositories
    # Repository that deals with persistence for the `Preset` entity.
    class Presets < InMemoryRepository
      def insert_from_file(path)
        raw_contents =
          case path
          when /\.json$/
            File.read(path)
          when /\.erb$/
            ERB.new(File.read(path)).result
          end

        if Application['base_url'].start_with? 'https://inferno-qa.healthit.gov'
          raw_contents.gsub!('https://inferno.healthit.gov', 'https://inferno-qa.healthit.gov')
        end

        preset_hash = JSON.parse(raw_contents)

        preset_hash.deep_symbolize_keys!
        preset_hash[:id] ||= SecureRandom.uuid
        preset = Entities::Preset.new(preset_hash)

        insert(preset)
      end

      def presets_for_suite(suite_id)
        all.select { |preset| preset.test_suite_id.to_s == suite_id.to_s }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
inferno_core-0.6.1 lib/inferno/repositories/presets.rb
inferno_core-0.6.0 lib/inferno/repositories/presets.rb
inferno_core-0.5.4 lib/inferno/repositories/presets.rb
inferno_core-0.5.3 lib/inferno/repositories/presets.rb