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



62
63
64
65
66
67
# File 'lib/falcon/configuration.rb', line 62

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

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



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

def configuration
  @configuration
end

#pathObject (readonly)

Returns the value of attribute path.



69
70
71
# File 'lib/falcon/configuration.rb', line 69

def path
  @path
end

Class Method Details

.load_file(configuration, path) ⇒ Object



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

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)


93
94
95
96
97
98
99
100
101
# File 'lib/falcon/configuration.rb', line 93

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

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



103
104
105
106
107
108
109
110
# File 'lib/falcon/configuration.rb', line 103

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



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

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

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



112
113
114
115
116
117
118
119
# File 'lib/falcon/configuration.rb', line 112

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



121
122
123
124
125
126
127
128
# File 'lib/falcon/configuration.rb', line 121

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

#supervisorObject



130
131
132
133
134
135
136
137
# File 'lib/falcon/configuration.rb', line 130

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