class OasDivider::RelativeDocumentReferencer

Attributes

root[RW]

Public Class Methods

execute(root, depth) click to toggle source
# File lib/oas_divider/relative_document_referencer.rb, line 3
def self.execute(root, depth)
  new(root, depth).execute
end
new(root, depth) click to toggle source
# File lib/oas_divider/relative_document_referencer.rb, line 7
def initialize(root, depth)
  @root = root
  @depth = depth
end

Public Instance Methods

convert(ref) click to toggle source
# File lib/oas_divider/relative_document_referencer.rb, line 35
def convert(ref)
  # componentから取得することしか考えない
  if ref.split('/')[2] === 'schemas'
    "../" * depth + "#{ref.split('/')[1..3].join('/')}.yml"
  else
    "../" * depth + "#{ref.split('/')[1..2].join('/')}.yml#/#{ref.split('/')[3]}"
  end
end
execute() click to toggle source
# File lib/oas_divider/relative_document_referencer.rb, line 12
def execute
  lookup(root)
  root
end
lookup(object) click to toggle source

hashで、keyが$refならconvert hashかarrayならlookup そうでないならなにもしない

# File lib/oas_divider/relative_document_referencer.rb, line 20
def lookup(object)
  if object.is_a? Array
    object.each { |value| lookup(value) if value.is_a?(Hash) || value.is_a?(Array) }
  else
    object.each do |key, value|
      set_converted_value(object, key, value) if key === "$ref"
      lookup(value) if value.is_a?(Hash) || value.is_a?(Array)
    end
  end
end
set_converted_value(object, key, value) click to toggle source
# File lib/oas_divider/relative_document_referencer.rb, line 31
def set_converted_value(object, key, value)
  object[key] = convert(value)
end