Class: Falcon::Configuration::Loader

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, root = nil) ⇒ Loader

Returns a new instance of Loader.



64
65
66
67
68
69
# File 'lib/falcon/configuration.rb', line 64

def initialize(configuration, root = nil)
	@loaded = {}
	@configuration = configuration
	@environments = {}
	@root = root
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



72
73
74
# File 'lib/falcon/configuration.rb', line 72

def configuration
  @configuration
end

#pathObject (readonly)

Returns the value of attribute path.



71
72
73
# File 'lib/falcon/configuration.rb', line 71

def path
  @path
end

Class Method Details

.load_file(configuration, path) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/falcon/configuration.rb', line 74

def self.load_file(configuration, path)
	path = File.realpath(path)
	root = File.dirname(path)
	
	loader = self.new(configuration, root)
	
	loader.instance_eval(File.read(path), path)
end

Instance Method Details

#add(name, *parents, &block) ⇒ Object

Raises:

  • (KeyError)


95
96
97
98
# File 'lib/falcon/configuration.rb', line 95

def add(name, *parents, &block)
	raise KeyError.new("#{name} is already set", key: name) if @environments.key?(name)
	@environments[name] = merge(name, *parents, &block)
end

#host(name, *parents, &block) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/falcon/configuration.rb', line 100

def host(name, *parents, &block)
	environment = merge(name, :host, *parents, &block)
	
	environment[:root] = @root
	environment[:authority] = name
	
	@configuration.add(environment.flatten)
end

#load(*features) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/falcon/configuration.rb', line 83

def load(*features)
	features.each do |feature|
		next if @loaded.include?(feature)
		
		relative_path = File.join(__dir__, "configuration", "#{feature}.rb")
		
		self.instance_eval(File.read(relative_path), relative_path)
		
		@loaded[feature] = relative_path
	end
end

#proxy(name, *parents, &block) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/falcon/configuration.rb', line 109

def proxy(name, *parents, &block)
	environment = merge(name, :proxy, *parents, &block)
	
	environment[:root] = @root
	environment[:authority] = name
	
	@configuration.add(environment.flatten)
end

#rack(name, *parents, &block) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/falcon/configuration.rb', line 118

def rack(name, *parents, &block)
	environment = merge(name, :rack, *parents, &block)
	
	environment[:root] = @root
	environment[:authority] = name
	
	@configuration.add(environment.flatten)
end

#supervisorObject



127
128
129
130
131
132
133
134
# File 'lib/falcon/configuration.rb', line 127

def supervisor
	name = File.join(@root, "supervisor")
	environment = merge(name, :supervisor)
	
	environment[:root] = @root
	
	@configuration.add(environment.flatten)
end