omnizip 0.3.52 → 0.3.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "lutaml/model"
4
+
3
5
  module Omnizip
4
6
  module Models
5
- # Represents an aggregated profiling report with hot path analysis
6
- class ProfileReport
7
- attr_reader :profile_name, :results, :hot_paths, :bottlenecks,
8
- :timestamp, :metadata
7
+ # Aggregated profiling report with hot path analysis.
8
+ #
9
+ # Serialized via lutaml-model — no hand-rolled +to_h+ / +to_json+.
10
+ # The +summary+ key serializes a nested Summary model built from
11
+ # the report's aggregates; hot paths and bottlenecks are the
12
+ # analyzer-supplied hashes.
13
+ class ProfileReport < Lutaml::Model::Serializable
14
+ # Aggregate block of {ProfileReport#to_hash}.
15
+ class Summary < Lutaml::Model::Serializable
16
+ attribute :total_execution_time, :double, default: 0.0
17
+ attribute :total_memory_allocated, :integer, default: 0
18
+ attribute :total_gc_runs, :integer, default: 0
19
+ attribute :operation_count, :integer, default: 0
20
+
21
+ key_value do
22
+ map "total_execution_time", to: :total_execution_time,
23
+ render_default: true, render_nil: true
24
+ map "total_memory_allocated", to: :total_memory_allocated,
25
+ render_default: true, render_nil: true
26
+ map "total_gc_runs", to: :total_gc_runs,
27
+ render_default: true, render_nil: true
28
+ map "operation_count", to: :operation_count,
29
+ render_default: true, render_nil: true
30
+ end
31
+ end
32
+
33
+ attribute :profile_name, :string
34
+ attribute :results, PerformanceResult, collection: true, default: []
35
+ attribute :hot_paths, :hash, collection: true, default: []
36
+ attribute :bottlenecks, :hash, collection: true, default: []
37
+ attribute :timestamp, :date_time, default: -> { Time.now }
38
+ attribute :metadata, :hash, default: {}
39
+ attribute :summary, Summary, method: :build_summary
40
+
41
+ key_value do
42
+ map "profile_name", to: :profile_name,
43
+ render_default: true, render_nil: true
44
+ map "timestamp", to: :timestamp,
45
+ render_default: true, render_nil: true
46
+ map "summary", to: :summary,
47
+ render_default: true, render_nil: true
48
+ map "results", to: :results,
49
+ render_default: true, render_nil: true
50
+ map "hot_paths", to: :hot_paths,
51
+ render_default: true, render_nil: true
52
+ map "bottlenecks", to: :bottlenecks,
53
+ render_default: true, render_nil: true
54
+ map "metadata", to: :metadata,
55
+ render_default: true, render_nil: true
56
+ end
9
57
 
10
- def initialize(
11
- profile_name:,
12
- results: [],
13
- hot_paths: [],
14
- bottlenecks: [],
15
- timestamp: Time.now,
16
- metadata: {}
17
- )
18
- @profile_name = profile_name
19
- @results = results
20
- @hot_paths = hot_paths
21
- @bottlenecks = bottlenecks
22
- @timestamp = timestamp
23
- @metadata = metadata
58
+ # lutaml-model 0.8.x does not render empty-collection defaults,
59
+ # so they are assigned explicitly to keep every key present.
60
+ def initialize(attrs = {})
61
+ super({ results: [], hot_paths: [], bottlenecks: [],
62
+ metadata: {} }.merge(attrs))
24
63
  end
25
64
 
26
65
  def total_execution_time
@@ -50,32 +89,27 @@ module Omnizip
50
89
  end
51
90
 
52
91
  def add_result(result)
53
- @results << result
92
+ results << result
54
93
  end
55
94
 
56
95
  def add_hot_path(hot_path)
57
- @hot_paths << hot_path
96
+ hot_paths << hot_path
58
97
  end
59
98
 
60
99
  def add_bottleneck(bottleneck)
61
- @bottlenecks << bottleneck
100
+ bottlenecks << bottleneck
62
101
  end
63
102
 
64
- def to_h
65
- {
66
- profile_name: profile_name,
67
- timestamp: timestamp.iso8601,
68
- summary: {
69
- total_execution_time: total_execution_time,
70
- total_memory_allocated: total_memory_allocated,
71
- total_gc_runs: total_gc_runs,
72
- operation_count: results.size,
73
- },
74
- results: results.map(&:to_h),
75
- hot_paths: hot_paths,
76
- bottlenecks: bottlenecks,
77
- metadata: metadata,
78
- }
103
+ # Serialized aggregate block.
104
+ #
105
+ # @return [Summary]
106
+ def build_summary
107
+ Summary.new(
108
+ total_execution_time: total_execution_time,
109
+ total_memory_allocated: total_memory_allocated,
110
+ total_gc_runs: total_gc_runs,
111
+ operation_count: results.size,
112
+ )
79
113
  end
80
114
  end
81
115
  end
@@ -87,7 +87,7 @@ module Omnizip
87
87
  ::File.open(archive_path, "rb") do |io|
88
88
  # Find the entry in reader
89
89
  reader_entry = reader.entries.find { |e| e.filename == entry.name }
90
- raise "Entry not found in archive: #{entry.name}" unless reader_entry
90
+ raise Errno::ENOENT, "Entry not found in archive: #{entry.name}" unless reader_entry
91
91
 
92
92
  # Seek to entry data
93
93
  io.seek(reader_entry.local_header_offset, ::IO::SEEK_SET)
@@ -288,7 +288,7 @@ module Omnizip
288
288
  @write_mutex.synchronize do
289
289
  # Check if file exists
290
290
  if ::File.exist?(dest_path) && !overwrite
291
- raise "File exists: #{dest_path}"
291
+ raise Errno::EEXIST, "File exists: #{dest_path}"
292
292
  end
293
293
 
294
294
  # Write file or create directory
@@ -93,7 +93,7 @@ module Omnizip
93
93
  # @param work [Fractor::Work] work item to process
94
94
  # @return [void]
95
95
  def submit(work)
96
- raise "Worker pool not started" unless @running
96
+ raise Omnizip::IOError, "Worker pool not started" unless @running
97
97
 
98
98
  if @continuous
99
99
  # In continuous mode, add to work queue
@@ -116,8 +116,8 @@ module Omnizip
116
116
  #
117
117
  # @return [void]
118
118
  def run
119
- raise "Can only run in batch mode" if @continuous
120
- raise "Worker pool not started" unless @running
119
+ raise Omnizip::IOError, "Can only run in batch mode" if @continuous
120
+ raise Omnizip::IOError, "Worker pool not started" unless @running
121
121
 
122
122
  @supervisor.run
123
123
 
@@ -33,7 +33,7 @@ module Omnizip
33
33
 
34
34
  # Generate a JSON report
35
35
  def generate_json_report
36
- JSON.pretty_generate(report.to_h)
36
+ JSON.pretty_generate(report.to_hash)
37
37
  end
38
38
 
39
39
  # Save report to file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Omnizip
4
- VERSION = "0.3.52"
4
+ VERSION = "0.3.53"
5
5
  end
@@ -402,7 +402,7 @@ module Omnizip
402
402
  ::File.open(@name, "rb") do |io|
403
403
  # Find the entry in reader
404
404
  reader_entry = @reader.entries.find { |e| e.filename == entry.name }
405
- raise "Entry not found in archive: #{entry.name}" unless reader_entry
405
+ raise Errno::ENOENT, "Entry not found in archive: #{entry.name}" unless reader_entry
406
406
 
407
407
  # Extract just the data
408
408
  io.seek(reader_entry.local_header_offset, ::IO::SEEK_SET)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omnizip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.52
4
+ version: 0.3.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.