magynhard/yaml_extend

cannot find yaml files that are extended

blset opened this issue · 3 comments

blset commented

if the yaml filesfile.ymland other.yml are in a directory called config

and the call YAML.ext_load_file 'config/file.yml' is issued with cwd one above config
then the other files that are extended are not found


# file.yml
extends: 
 - 'other.yml' # not found
 - 'config/other.yml'  # not found either

does not work with path relative to file.yml or relative to cwd

Hi @blset , thank you for your question.

I can not reproduce your problem, relative path from the config file is working fine for me, as do the rspec tests as well.

An example file structure:

main.rb
config/file.yml
config/other.yml

The files containing that code:

# main.rb
require 'yaml_extend'
config = YAML.ext_load_file 'config/file.yml'
p config
# file.yml
extends:
        - 'other.yml'
core: 'core string'
# other.yml
other_options: 'some string'

Running the program
ruby main.rb
gives the following output:

{"core"=>"core string", "other_options"=>"some string"}

Conclusion

There might have been a typo in your code or it is a platform specific issue.

Can you provide me information about your

  • ruby version (ruby -v) and
  • platform (Operating System)
blset commented

ruby 2.6.3 on ubuntu 18 04 LTS
but you are right, that must have been a typo, I make it work now

thank you very much

just one more question, while we are on conversation

if I put the extend key under an option key, does that mean the yaml other file is loaded under the option key ?

#other .yml
key1: o
key2: o


# main.yml
option:
   extend: 'other.yml'

key1: 1

this result or :


key1: 1
option:
    key1: o
    key2: o

this result

key1: o
key2: o

Thank you for your reply.

The extension always takes place at root level, independent of the key and its level.
The YAML files are just merged together, that's it.

So your last result example is what will happen.