Coder Social home page Coder Social logo

Comments (5)

havocp avatar havocp commented on July 4, 2024

There are some docs on doing something like this here in the Akka docs I think, search for "lift-a-subtree" in http://doc.akka.io/docs/akka/snapshot/general/configuration.html

Those docs talk about config.getConfig("b1").withFallback(config.withOnlyPath("a")) or something along those lines. I guess the issue is that you want to stick a prefix on b1 (the subtree doesn't start with the root).

So maybe a method like prefix? config.getConfig("b1").prefix("a.b").withFallback(config.withOnlyPath("a")) or so? Does that work?

from config.

havocp avatar havocp commented on July 4, 2024

Possible patch at havocp-multiline-strings...havocp-under-path

Wondering if a better or additional change would be to just add a "setter" method to Config/ConfigObject (equivalent of Map.put but returning a new object instead of mutating). Have to think what it would be called; to be most convenient it should be something(String path, Object anything) and use ConfigValueFactory.fromAnyRef to interpret anything, I'm thinking. So withValue I'd expect to be withValue(String path, ConfigValue value) instead. withAnyRef would be most consistent with existing method names. Just something concise like plus or add or something might work too but those really should take a ConfigValue to be consistent with the overall API of Config/ConfigObject (they are String,ConfigValue mappings). Having the method take ConfigValue instead of Object would probably be clearer, but also too verbose to use in the common cases that people would use this.

from config.

cos avatar cos commented on July 4, 2024

Thank you for your quick reply and patch. The patch already makes things much easier.

As for the a put-like interface, probably plus would be most consistent with Scala's Map interface and I agree it should take a ConfigValue, not anything.

Regarding ConfigValueFactory, syntax-wise it would be cool to do ConfigValueFactory.at("some.path").fromAnyRef. It would be achievable by having a factory object with "some.path" built-in. I haven't looked at the code to see how easy would that be to implement, tho.

from config.

havocp avatar havocp commented on July 4, 2024

I added a withValue() also and merged to master. I went with withValue() because we have withoutKey() already (rather than "minus") so withValue() seems to go with it better. Didn't want to have both "minus" and "withoutKey" as synonyms, didn't want to have "plus" and "withoutKey" as opposites that didn't go together. I guess it's good to stick to this "with" convention too.

More convenience API would be possible but I guess just keeping it simple for now. In Scala one might make things a good bit nicer by importing some implicit conversions from various types to ConfigValue, like:

  implicit int2configvalue(v: Int): ConfigValue = ConfigValueFactory.fromAnyRef(v)

Then you could just write config.withValue("a.b.", 42) etc. I believe.

from config.

cos avatar cos commented on July 4, 2024

Sounds very good. Thank you!

from config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.