Gem 一个读写配置文件的 gem

simlegate · September 10, 2013 · Last by simlegate replied at January 24, 2014 · 2770 hits

https://github.com/simlegate/kstarv 想法来源于项目中需要读写 Centos 的网卡配置文件

DEVICE=eth0
HWADDR=00:1E:67:24:E8:2D
TYPE=Ethernet
UUID=8dc70db4-9c80-4757-807b-6419d864f74d
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.201
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
BORADCAST=192.168.0.255

基本用法:

@kv = Kstarv.from(/path/to/config) 
@kv.ipaddr  # => 127.0.0.1
@kv.write

感谢楼主分享。已经采用,挺好使的。要是能加上对于配置文件中注释的过滤就更完美了。

You need to Sign in before reply, if you don't have an account, please Sign up first.