Class: Metrics::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/compose_compiler_metrics/metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Loader

Returns a new instance of Loader.



54
55
56
# File 'lib/compose_compiler_metrics/metrics.rb', line 54

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



52
53
54
# File 'lib/compose_compiler_metrics/metrics.rb', line 52

def path
  @path
end

Instance Method Details

#loadObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/compose_compiler_metrics/metrics.rb', line 62

def load
  advanced_metrics_hash = metrics_hash.each.with_object({}) do |(k, v), h|
    h[k] = v

    case k
    when "skippableComposables"
      h["unskippableComposables"] = metrics_hash["totalComposables"] - metrics_hash["skippableComposables"]
    when "restartableComposables"
      h["unrestartableComposables"] = metrics_hash["totalComposables"] - metrics_hash["restartableComposables"]
    end
  end

  Metrics.new(advanced_metrics_hash)
end

#metrics_hashObject



58
59
60
# File 'lib/compose_compiler_metrics/metrics.rb', line 58

def metrics_hash
  @metrics_hash ||= JSON.parse(File.read(path))
end