Class: BoringBuilder::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/boringbuilder/config_file.rb

Constant Summary collapse

DEFAULT_PATH =
"config/boringbuilder.rb"
THREAD_KEY =
:boringbuilder_config_file

Class Method Summary collapse

Class Method Details

.configure {|state.fetch(:configuration)| ... } ⇒ Object

Yields:

  • (state.fetch(:configuration))

Raises:



31
32
33
34
35
36
37
# File 'lib/boringbuilder/config_file.rb', line 31

def configure
  state = Thread.current[THREAD_KEY]
  raise ConfigurationError, "BoringBuilder.configure is only available while loading a config file" unless state

  state[:applied] = true
  yield state.fetch(:configuration)
end

.load(path, configuration) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/boringbuilder/config_file.rb', line 19

def load(path, configuration)
  previous = Thread.current[THREAD_KEY]
  state = { configuration: configuration, applied: false }
  Thread.current[THREAD_KEY] = state
  Kernel.load(path.to_s)
  raise ConfigurationError, "#{path} must call BoringBuilder.configure" unless state[:applied]

  configuration
ensure
  Thread.current[THREAD_KEY] = previous
end

.resolve(root, requested = :auto) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
# File 'lib/boringbuilder/config_file.rb', line 9

def resolve(root, requested = :auto)
  return if requested == false || requested.nil?

  path = root.join(requested == :auto ? DEFAULT_PATH : requested).expand_path
  return path if path.file?
  return if requested == :auto

  raise ConfigurationError, "BoringBuilder config file does not exist: #{path}"
end