sunaku / wmiirc

Ruby configuration for WMII window manager
ISC License
82 stars 26 forks source link

Caching complete config in one file #9

Closed nougad closed 14 years ago

nougad commented 14 years ago

I thought a little bit about using yaml-references in config file. e.g.:

display:
  status:
    wlan0:
      label: &geninit
         .. display status of init script ...
      path: /etc/init.d/net.wlan0
    eth0:
      label: *geninit
      path: /etc/init.d/net.wlan0

But this would make it necessary to load complete config at once. Perhaps it would be a nice Idea to cache the complete config in an special file and only diff the timestamps of both files. If config is newer rebuild cache and load it else load only cache.

I tested the cofnig with references and it works pretty well if whole config is in one file of course.

Caching the config is a little bit ugly (I think the performance improvement will be minimal) but perhaps references can make some pretty things possible. What do you think?

sunaku commented 14 years ago

If we simply inject the target files of include directives and make one giant YAML file, we cannot rely on YAML to do merging because it overwrites:

>> YAML.load "a: b\na: c\n"
=> {"a"=>"c"}

So I am forced to evaluate each import target as an individual YAML document. When doing so, invalid alias dereferences are converted into YAML::Syck::BadAlias objects, but alias definitions are not:

>> YAML.load "a: b\na: *c\nx: &foo"
=> {"a"=>#<YAML::Syck::BadAlias:0x86d142c @name="c">, "x"=>nil}

If you can figure out how to retain YAML alias definitions in the result of YAML.load() then maybe we can walk the tree and perform alias substitutions ourselves.

Otherwise I do not know how to implement your feature request.

nougad commented 14 years ago

Uh, I forgot the merging. I tested it obviously with some special cases and doesn't try merging. Of course it would overwrite anything defined before.

Ok, then please forget this idea. It is really impossible. Sorry for the fatal mistake.

Btw:

Otherwise I do not know how to implement your feature request.

you needn't to write this code for me, I only want some feedback before I start coding ... obviously this was a good decision ;-)

thanks for your great framework and happy coding