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

Support !include #5

@choffmeister

Description

@choffmeister

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions