Class: PetriDish::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/petri_dish/config.rb

Constant Summary collapse

REQUIRED_KEYS =
%w[name description environment runtime].freeze
REQUIRED_ENV_KEYS =
%w[name].freeze
VALID_PROMPT_MODES =
%w[accept deny].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_dir) ⇒ Config

Returns a new instance of Config.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/petri_dish/config.rb', line 14

def initialize(test_dir)
  @test_dir = Pathname.new(test_dir).expand_path
  config_path = @test_dir / "config.yml"
  raise "Config not found: #{config_path}" unless config_path.exist?

  data = YAML.safe_load(config_path.read, permitted_classes: [Symbol])
  validate!(data)

  @name = data["name"]
  @description = data["description"]
  @environment = parse_environment(data["environment"])
  @runtime = parse_runtime(data["runtime"])
  @prompt_mode = parse_prompt_mode(data["prompt_mode"])
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/petri_dish/config.rb', line 12

def description
  @description
end

#environmentObject (readonly)

Returns the value of attribute environment.



12
13
14
# File 'lib/petri_dish/config.rb', line 12

def environment
  @environment
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/petri_dish/config.rb', line 12

def name
  @name
end

#prompt_modeObject (readonly)

Returns the value of attribute prompt_mode.



12
13
14
# File 'lib/petri_dish/config.rb', line 12

def prompt_mode
  @prompt_mode
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



12
13
14
# File 'lib/petri_dish/config.rb', line 12

def runtime
  @runtime
end

#test_dirObject (readonly)

Returns the value of attribute test_dir.



12
13
14
# File 'lib/petri_dish/config.rb', line 12

def test_dir
  @test_dir
end

Instance Method Details

#prompt_pathObject



29
30
31
# File 'lib/petri_dish/config.rb', line 29

def prompt_path
  test_dir / "prompt.md"
end