Module: SprocketsDerailleur

Defined in:
lib/sprockets-derailleur/file_store.rb,
lib/sprockets-derailleur.rb,
lib/sprockets-derailleur/configuration.rb,
lib/sprockets-derailleur/file_store_extension.rb

Overview

The Sprockets::Cache::FileStore is not thread/parallel safe. This one uses file locks to be safe.

Defined Under Namespace

Modules: FileStoreExtension Classes: Configuration, FileStore

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



12
13
14
# File 'lib/sprockets-derailleur.rb', line 12

def self.configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



16
17
18
# File 'lib/sprockets-derailleur.rb', line 16

def self.configure
  yield(configuration)
end

.number_of_processorsObject



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

def self.number_of_processors
  if RUBY_PLATFORM =~ /linux/
    return `cat /proc/cpuinfo | grep processor | wc -l`.to_i
  elsif RUBY_PLATFORM =~ /darwin/
    return `sysctl -n hw.physicalcpu`.to_i
  elsif RUBY_PLATFORM =~ /win32/
    # this works for windows 2000 or greater
    require 'win32ole'
    wmi = WIN32OLE.connect("winmgmts://")
    wmi.ExecQuery("select * from Win32_ComputerSystem").each do |system|
      begin
        processors = system.NumberOfLogicalProcessors
      rescue
        processors = 0
      end
      return [system.NumberOfProcessors, processors].max
    end
  end
  raise "can't determine 'number_of_processors' for '#{RUBY_PLATFORM}'"
end

.prepend_file_store_if_requiredObject



49
50
51
52
53
54
55
# File 'lib/sprockets-derailleur.rb', line 49

def self.prepend_file_store_if_required
  if SprocketsDerailleur.configuration.use_sprockets_derailleur_file_store
    Sprockets::Cache::FileStore.class_eval do
      prepend SprocketsDerailleur::FileStoreExtension
    end
  end
end

.worker_countObject



41
42
43
44
45
46
47
# File 'lib/sprockets-derailleur.rb', line 41

def self.worker_count
  worker_count = SprocketsDerailleur.configuration.worker_count || ENV['SPROCKETS_DERAILLEUR_WORKER_COUNT'].to_i
  return worker_count if worker_count > 0
  number_of_processors
rescue
  1
end