class Xapixctl::SyncCli::ResourcePath

Public Class Methods

new(shell, path) click to toggle source
# File lib/xapixctl/sync_cli.rb, line 162
def initialize(shell, path)
  @shell = shell
  @path = path
  @resource_files = []
end

Public Instance Methods

load_resource(res_name, &block) click to toggle source
# File lib/xapixctl/sync_cli.rb, line 190
def load_resource(res_name, &block)
  Util.resources_from_file(@path.join("#{res_name}.yaml"), ignore_missing: false, &block)
end
load_resources(&block) click to toggle source
# File lib/xapixctl/sync_cli.rb, line 186
def load_resources(&block)
  Util.resources_from_file(@path, ignore_missing: true, &block)
end
remove_outdated_resources() click to toggle source
# File lib/xapixctl/sync_cli.rb, line 194
def remove_outdated_resources
  (@path.glob('*.yaml') - @resource_files).each do |outdated_file|
    outdated_file.delete
    say "removed #{outdated_file}"
  end
end
write_file(content, filename) click to toggle source
# File lib/xapixctl/sync_cli.rb, line 168
def write_file(content, filename)
  @path.mkpath
  unless @path.directory? && @path.writable?
    warn "Cannot write to #{@path}, please check directory exists and is writable"
    exit 1
  end
  file = @path.join(filename)
  file.write(content)
  say "updated #{file}..."
  file
end
write_resource_yaml(res_details, res_name) click to toggle source
# File lib/xapixctl/sync_cli.rb, line 180
def write_resource_yaml(res_details, res_name)
  file = write_file(res_details.to_yaml, "#{res_name}.yaml")
  @resource_files << file
  file
end