未验证 提交 f24840a4 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #40250 from composerinteralia/cidr-public-methods

Use `IPAddr#prefix` for postgres cidr type
......@@ -12,19 +12,17 @@ def type
end
def type_cast_for_schema(value)
subnet_mask = value.instance_variable_get(:@mask_addr)
# If the subnet mask is equal to /32, don't output it
if subnet_mask == (2**32 - 1)
if value.prefix == 32
"\"#{value}\""
else
"\"#{value}/#{subnet_mask.to_s(2).count('1')}\""
"\"#{value}/#{value.prefix}\""
end
end
def serialize(value)
if IPAddr === value
"#{value}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
"#{value}/#{value.prefix}"
else
value
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册