Class: Serialbench::Models::ResultStore

Inherits:
Object
  • Object
show all
Defined in:
lib/serialbench/models/result_store.rb

Constant Summary collapse

DEFAULT_BASE_PATH =
'results'
RUNS_PATH =
'runs'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path = DEFAULT_BASE_PATH) ⇒ ResultStore

Returns a new instance of ResultStore.



14
15
16
17
# File 'lib/serialbench/models/result_store.rb', line 14

def initialize(base_path = DEFAULT_BASE_PATH)
  @base_path = base_path
  ensure_results_directory
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



12
13
14
# File 'lib/serialbench/models/result_store.rb', line 12

def base_path
  @base_path
end

Class Method Details

.defaultObject



19
20
21
# File 'lib/serialbench/models/result_store.rb', line 19

def self.default
  @default ||= new
end

Instance Method Details

#ensure_results_directoryObject



65
66
67
# File 'lib/serialbench/models/result_store.rb', line 65

def ensure_results_directory
  FileUtils.mkdir_p(runs_path) unless Dir.exist?(runs_path)
end

#find_runs(tags: nil, limit: nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/serialbench/models/result_store.rb', line 28

def find_runs(tags: nil, limit: nil)
  runs = Result.find_all(runs_path)

  runs = runs.select { |run| (Array(tags) - run.tags).empty? } if tags

  limit ? runs.first(limit) : runs
end

#runs_pathObject

Run management



24
25
26
# File 'lib/serialbench/models/result_store.rb', line 24

def runs_path
  File.join(@base_path, RUNS_PATH)
end

#valid?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/serialbench/models/result_store.rb', line 61

def valid?
  validate_structure.empty?
end

#validate_structureObject

Validation



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/serialbench/models/result_store.rb', line 37

def validate_structure
  errors = []

  # Check base structure
  errors << "Base path does not exist: #{@base_path}" unless Dir.exist?(@base_path)
  errors << "Runs directory does not exist: #{runs_path}" unless Dir.exist?(runs_path)

  # Validate individual runs
  if Dir.exist?(runs_path)
    Dir.glob(File.join(runs_path, '*')).each do |run_path|
      next unless Dir.exist?(run_path)

      begin
        run = Result.load(run_path)
        run.validate!
      rescue StandardError => e
        errors << "Invalid result at #{run_path}: #{e.message}"
      end
    end
  end

  errors
end