class RedfishTools::DataStore

Constants

Resource

Public Class Methods

new(base_path) click to toggle source
# File lib/redfish_tools/datastore.rb, line 9
def initialize(base_path)
  @base_path = File.expand_path(base_path)
  @overlay = {}

  root_file = File.join(@base_path, "redfish", "v1", "index.json")
  raise "Invalid recording folder" unless File.file?(root_file)
end

Public Instance Methods

get(id) click to toggle source
# File lib/redfish_tools/datastore.rb, line 17
def get(id)
  id = id.chomp("/")
  @overlay[id] = @overlay.fetch(id, load_resource(id))
end
set(id, body, headers: nil, time: nil, parent: nil) click to toggle source
# File lib/redfish_tools/datastore.rb, line 22
def set(id, body, headers: nil, time: nil, parent: nil)
  @overlay[id] = Resource.new(id, body, headers, time, parent)
end

Private Instance Methods

load_body(id) click to toggle source
# File lib/redfish_tools/datastore.rb, line 32
def load_body(id)
  load_json(File.join(@base_path, id, "index.json"))
end
load_headers(id) click to toggle source
# File lib/redfish_tools/datastore.rb, line 36
def load_headers(id)
  headers = load_json(File.join(@base_path, id, "headers.json"))
  headers && headers["GET"]
end
load_json(path) click to toggle source
# File lib/redfish_tools/datastore.rb, line 46
def load_json(path)
  File.readable?(path) ? JSON.parse(File.read(path)) : nil
end
load_resource(id) click to toggle source
# File lib/redfish_tools/datastore.rb, line 28
def load_resource(id)
  Resource.new(id, load_body(id), load_headers(id), load_time(id))
end
load_time(id) click to toggle source
# File lib/redfish_tools/datastore.rb, line 41
def load_time(id)
  times = load_json(File.join(@base_path, id, "time.json"))
  times && times["GET_Time"]&.to_f
end