Skip to content

Commit d84c082

Browse files
committed
change how config inheriting works
1 parent 895b695 commit d84c082

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

pgmoon/init.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -883,14 +883,20 @@ do
883883
}
884884
_base_0.__index = _base_0
885885
_class_0 = setmetatable({
886-
__init = function(self, config)
887-
if config == nil then
888-
config = { }
889-
end
890-
self.config = config
891-
assert(not getmetatable(self.config), "options argument must not have a metatable to allow default configuration to be inherited")
892-
setmetatable(self.config, {
893-
__index = self.default_config
886+
__init = function(self, _config)
887+
if _config == nil then
888+
_config = { }
889+
end
890+
self._config = _config
891+
self.config = setmetatable({ }, {
892+
__index = function(t, key)
893+
local value = self._config[key]
894+
if value == nil then
895+
return self.default_config[key]
896+
else
897+
return value
898+
end
899+
end
894900
})
895901
self.sock, self.sock_type = socket.new(self.config.socket_type)
896902
end,

pgmoon/init.moon

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,15 @@ class Postgres
171171
-- ssl_verify: verify the certificate
172172
-- cqueues_openssl_context: manually created openssl.ssl.context for cqueues sockets
173173
-- luasec_opts: manually created options for LuaSocket ssl connections
174-
new: (@config={}) =>
175-
assert not getmetatable(@config),
176-
"options argument must not have a metatable to allow default configuration to be inherited"
177-
178-
setmetatable @config, __index: @default_config
174+
new: (@_config={}) =>
175+
@config = setmetatable {}, {
176+
__index: (t, key) ->
177+
value = @_config[key]
178+
if value == nil
179+
@default_config[key]
180+
else
181+
value
182+
}
179183

180184
@sock, @sock_type = socket.new @config.socket_type
181185

0 commit comments

Comments
 (0)