Class: Nanoc::CLI::Commands::Compile::GCController

Inherits:
Listener
  • Object
show all
Defined in:
lib/nanoc/cli/commands/compile.rb

Overview

Controls garbage collection so that it only occurs once every 20 items

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (GCController) initialize(params = {})

Returns a new instance of GCController



262
263
264
# File 'lib/nanoc/cli/commands/compile.rb', line 262

def initialize(params={})
  @gc_count = 0
end

Class Method Details

+ (Boolean) enable_for?(command_runner)

Returns:

  • (Boolean)

See Also:

  • Listener#enable_for?


258
259
260
# File 'lib/nanoc/cli/commands/compile.rb', line 258

def self.enable_for?(command_runner)
  ! ENV.has_key?('TRAVIS')
end

Instance Method Details

- (Object) start

See Also:



267
268
269
270
271
272
273
274
275
276
# File 'lib/nanoc/cli/commands/compile.rb', line 267

def start
  Nanoc::NotificationCenter.on(:compilation_started) do |rep|
    if @gc_count % 20 == 0
      GC.enable
      GC.start
      GC.disable
    end
    @gc_count += 1
  end
end

- (Object) stop

See Also:



279
280
281
282
# File 'lib/nanoc/cli/commands/compile.rb', line 279

def stop
  super
  GC.enable
end