class R2OAS::Schema::V3::BaseFileManager

Attributes

original_path[RW]

Public Class Methods

new(path, path_type = :full) click to toggle source

e.x.) openapi_path = “#/components/schemas/Account”

Calls superclass method R2OAS::Base::new
# File lib/r2-oas/schema/v3/manager/file/base_file_manager.rb, line 13
def initialize(path, path_type = :full)
  super()
  @ext_name = :yml
  @path_type = path_type
  @original_path = path
  @relative_save_file_path = PathnameManager.new(path, path_type).relative_save_file_path
end

Public Instance Methods

delete() click to toggle source
# File lib/r2-oas/schema/v3/manager/file/base_file_manager.rb, line 21
def delete
  File.delete(save_file_path) if FileTest.exists?(save_file_path)
end
descendants_paths() click to toggle source
# File lib/r2-oas/schema/v3/manager/file/base_file_manager.rb, line 60
def descendants_paths
  []
end
load_data() click to toggle source
# File lib/r2-oas/schema/v3/manager/file/base_file_manager.rb, line 47
def load_data
  case @ext_name
  when :yml
    if FileTest.exists?(save_file_path)
      YAML.load_file(save_file_path)
    else
      {}
    end
  else
    raise NoSupportError, "Do not support @ext_name: #{@ext_name}"
  end
end
save(data) click to toggle source
# File lib/r2-oas/schema/v3/manager/file/base_file_manager.rb, line 25
def save(data)
  abs_dir = File.dirname(save_file_path)
  FileUtils.mkdir_p(abs_dir) unless FileTest.exists?(abs_dir)
  File.write(save_file_path, data)
end
save_after_deep_merge(data) click to toggle source
# File lib/r2-oas/schema/v3/manager/file/base_file_manager.rb, line 31
def save_after_deep_merge(data)
  result = load_data.deep_merge(data)
  save(result.to_yaml)
end
save_file_path(type: :full) click to toggle source
# File lib/r2-oas/schema/v3/manager/file/base_file_manager.rb, line 36
def save_file_path(type: :full)
  file_path = File.expand_path(@relative_save_file_path)

  case type
  when :relative
    file_path.sub(%r{^#{Dir.getwd}/?}, '')
  else
    file_path
  end
end