Class: Inferno::Repositories::Presets

Inherits:
InMemoryRepository show all
Defined in:
lib/inferno/repositories/presets.rb

Overview

Repository that deals with persistence for the Preset entity.

Instance Method Summary collapse

Methods inherited from InMemoryRepository

all, #exists?, #find, #insert

Instance Method Details

#insert_from_file(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/inferno/repositories/presets.rb', line 10

def insert_from_file(path)
  case path
  when /\.json$/
    preset_hash = JSON.parse(File.read(path))
  when /\.erb$/
    templated = ERB.new(File.read(path)).result
    preset_hash = JSON.parse(templated)
  end

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

  insert(preset)
end

#presets_for_suite(suite_id) ⇒ Object



26
27
28
# File 'lib/inferno/repositories/presets.rb', line 26

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