Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Support !include #5

Open
choffmeister opened this issue Feb 7, 2015 · 1 comment
Open

Support !include #5

choffmeister opened this issue Feb 7, 2015 · 1 comment

Comments

@choffmeister
Copy link

Seems like this is not active anymore, but in case, you start again anytime and want to support imports: The following does the trick:

Psych.add_domain_type 'include', 'include' do |_, value|
  case value
    when /^https?:\/\//
      # TODO implement remote loading of included files
      ''
    else
      case value
        when /\.raml$/
          read_yaml(value)
        when /\.ya?ml$/
          read_yaml(value)
        else
          File.read(value)
      end
  end
end

def read_yaml(path)
  # change working directory so that !includes work properly
  pwd_old = Dir.pwd
  Dir.chdir(File.dirname(path))
  raw = File.read(File.basename(path))
  node = YAML.load(raw)
  Dir.chdir(pwd_old)
  node
end
@zlx
Copy link

zlx commented Feb 24, 2016

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants