class Bump::CLI::References

Attributes

root_path[R]

Public Class Methods

new(root_path: "") click to toggle source
# File lib/bump/cli/references.rb, line 7
def initialize(root_path: "")
  @root_path = root_path
end

Public Instance Methods

load(definition) click to toggle source
# File lib/bump/cli/references.rb, line 11
def load(definition)
  traverse_and_load_external_references(definition) if definition.is_a?(Enumerable)
end

Private Instance Methods

absolute_path?(path) click to toggle source
# File lib/bump/cli/references.rb, line 63
def absolute_path?(path)
  path.start_with?("/")
end
cleanup_reference(reference) click to toggle source
# File lib/bump/cli/references.rb, line 43
def cleanup_reference(reference)
  reference.sub(/#.*/, "")
end
external?(reference) click to toggle source
# File lib/bump/cli/references.rb, line 55
def external?(reference)
  !reference.start_with?("#")
end
load_external_reference(reference) click to toggle source
# File lib/bump/cli/references.rb, line 35
def load_external_reference(reference)
  if self[reference].nil?
    base_reference = cleanup_reference(reference)
    location = prepare_location(base_reference)
    self[base_reference] = Resource.read(location)
  end
end
prepare_location(reference) click to toggle source
# File lib/bump/cli/references.rb, line 47
def prepare_location(reference)
  if url?(reference) || absolute_path?(reference)
    reference
  else
    root_path + reference
  end
end
traverse_and_load_external_references(current) click to toggle source
# File lib/bump/cli/references.rb, line 19
def traverse_and_load_external_references(current)
  current.each do |key, value|
    if key == "$ref"
      load_external_reference(value) if external?(value)
    elsif value.is_a?(Hash)
      traverse_and_load_external_references(value)
    elsif value.is_a?(Array)
      value.each do |array_value|
        if array_value.is_a?(Hash)
          traverse_and_load_external_references(array_value)
        end
      end
    end
  end
end
url?(path) click to toggle source
# File lib/bump/cli/references.rb, line 59
def url?(path)
  path.start_with?("http")
end