Class: Falcon::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/configuration.rb

Overview

Manages environments which describes how to host a specific application.

Environments are key-value maps with lazy value resolution. An environment can inherit from a parent environment, which can provide defaults

A typical configuration file might look something like:

~~~ ruby #!/usr/bin/env falcon-host # frozen_string_literal: true

load :rack, :self_signed_tls, :supervisor

supervisor

rack ‘hello.localhost’, :self_signed_tls do end ~~~

Defined Under Namespace

Classes: Loader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize an empty configuration.



46
47
48
# File 'lib/falcon/configuration.rb', line 46

def initialize
	@environments = {}
end

Instance Attribute Details

#environmentsObject (readonly)

The map of named environments.



52
53
54
# File 'lib/falcon/configuration.rb', line 52

def environments
  @environments
end

Instance Method Details

#add(environment) ⇒ Object

Add the named environment to the configuration.

Raises:

  • (KeyError)


69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/falcon/configuration.rb', line 69

def add(environment)
	name = environment.name
	
	unless name
		raise ArgumentError, "Environment name is nil #{environment.inspect}"
	end
	
	environment = environment.flatten
	
	raise KeyError.new("#{name.inspect} is already set", key: name) if @environments.key?(name)
	
	@environments[name] = environment
end

#each(key = :authority) ⇒ Object

Enumerate all environments that have the specified key.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/falcon/configuration.rb', line 56

def each(key = :authority)
	return to_enum(key) unless block_given?
	
	@environments.each do |name, environment|
		environment = environment.flatten
		
		if environment.include?(key)
			yield environment
		end
	end
end

#load_file(path) ⇒ Object

Load the specified configuration file. See Falcon::Configuration::Loader.load_file for more details.



84
85
86
# File 'lib/falcon/configuration.rb', line 84

def load_file(path)
	Loader.load_file(self, path)
end