Class: LibyearBundler::Reports::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/libyear_bundler/reports/base.rb

Overview

Base class for all reporters. Should only be concerned with presentation, nothing else.

Subclasses should implement the ‘#write` method.

Direct Known Subclasses

Console, JSON

Instance Method Summary collapse

Constructor Details

#initialize(gems, ruby, options, io) ⇒ Base

‘gems` - Array of `::LibyearBundler::Models::Gem` instances `options` - Instance of `::LibyearBundler::Options`



9
10
11
12
13
14
# File 'lib/libyear_bundler/reports/base.rb', line 9

def initialize(gems, ruby, options, io)
  @gems = gems
  @ruby = ruby
  @options = options
  @io = io
end

Instance Method Details

#to_hObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/libyear_bundler/reports/base.rb', line 20

def to_h
  @_to_h ||=
    begin
      gems = sorted_gems(@gems)
      summary = {
        gems: gems,
        sum_libyears: 0.0
      }
      gems.each { |gem| increment_metrics_summary(gem, summary) }

      begin
        increment_metrics_summary(@ruby, summary) if @ruby.outdated?
      rescue StandardError => e
        warn "Unable to calculate libyears for ruby itself: #{e}"
      end

      summary
    end
end

#writeObject

Raises:

  • (NoMethodError)


16
17
18
# File 'lib/libyear_bundler/reports/base.rb', line 16

def write
  raise NoMethodError, "Implement in subclass"
end