sprockets-derailleur 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sprockets-derailleur.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Steel Fu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Sprockets::Derailleur
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sprockets-derailleur'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sprockets-derailleur
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,119 @@
1
+ require "sprockets-derailleur/version"
2
+ require "sprockets"
3
+
4
+ module Sprockets
5
+ class Manifest
6
+ attr_reader :workers
7
+
8
+ alias_method :old_initialize, :initialize
9
+ def initialize(environment, path, workers=1)
10
+ @workers = workers
11
+ old_initialize(environment, path)
12
+ end
13
+
14
+ alias_method :compile_with_workers, :compile
15
+ def compile(*args)
16
+ time = Benchmark.measure do
17
+ paths = environment.each_logical_path(*args).to_a +
18
+ args.flatten.select { |fn| Pathname.new(fn).absolute? if fn.is_a?(String)}
19
+
20
+ logger.warn "Initializing #{@workers} workers"
21
+
22
+ workers = []
23
+ @workers.times do
24
+ workers << worker(paths)
25
+ end
26
+
27
+ reads = workers.map{|worker| worker[:read]}
28
+ writes = workers.map{|worker| worker[:write]}
29
+
30
+ index = 0
31
+ finished = 0
32
+
33
+ loop do
34
+ break if finished >= paths.size
35
+
36
+ ready = IO.select(reads, writes)
37
+ ready[0].each do |readable|
38
+ data = Marshal.load(readable)
39
+ assets.merge! data["assets"]
40
+ files.merge! data["files"]
41
+ finished += 1
42
+ end
43
+
44
+ ready[1].each do |write|
45
+ break if index >= paths.size
46
+
47
+ Marshal.dump(index, write)
48
+ index += 1
49
+ end
50
+ end
51
+
52
+ logger.debug "Cleaning up workers"
53
+
54
+ workers.each do |worker|
55
+ worker[:read].close
56
+ worker[:write].close
57
+ end
58
+
59
+ workers.each do |worker|
60
+ Process.wait worker[:pid]
61
+ end
62
+
63
+ save
64
+ end
65
+
66
+ logger.warn "Completed compiling assets (#{(time.real * 100).round / 100.0}s)"
67
+ end
68
+
69
+ def worker(paths)
70
+ child_read, parent_write = IO.pipe
71
+ parent_read, child_write = IO.pipe
72
+
73
+ pid = fork do
74
+ begin
75
+ parent_write.close
76
+ parent_read.close
77
+
78
+ while !child_read.eof?
79
+ path = paths[Marshal.load(child_read)]
80
+
81
+ time = Benchmark.measure do
82
+ if asset = find_asset(path)
83
+ data = {'assets' => {}, 'files' => {}}
84
+
85
+ data['files'][asset.digest_path] = {
86
+ 'logical_path' => asset.logical_path,
87
+ 'mtime' => asset.mtime.iso8601,
88
+ 'size' => asset.bytesize,
89
+ 'digest' => asset.digest
90
+ }
91
+ data['assets'][asset.logical_path] = asset.digest_path
92
+
93
+ target = File.join(dir, asset.digest_path)
94
+
95
+ if File.exist?(target)
96
+ logger.debug "Skipping #{target}, already exists"
97
+ else
98
+ logger.debug "Writing #{target}"
99
+ asset.write_to target
100
+ end
101
+
102
+ Marshal.dump(data, child_write)
103
+ end
104
+ end
105
+ logger.warn "Compiled #{path} (#{(time.real * 1000).round}ms)"
106
+ end
107
+ ensure
108
+ child_read.close
109
+ child_write.close
110
+ end
111
+ end
112
+
113
+ child_read.close
114
+ child_write.close
115
+
116
+ {:read => parent_read, :write => parent_write, :pid => pid}
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ module Derailleur
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sprockets-derailleur/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sprockets-derailleur"
8
+ gem.version = Sprockets::Derailleur::VERSION
9
+ gem.authors = ["Steel Fu"]
10
+ gem.email = ["steelfu@gmail.com"]
11
+ gem.description = %q{Speed up sprockets compiling by forking processes}
12
+ gem.summary = %q{Multi process sprockets compiling}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-derailleur
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Steel Fu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-03 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Speed up sprockets compiling by forking processes
22
+ email:
23
+ - steelfu@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - LICENSE.txt
34
+ - README.md
35
+ - Rakefile
36
+ - lib/sprockets-derailleur.rb
37
+ - lib/sprockets-derailleur/version.rb
38
+ - sprockets-derailleur.gemspec
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Multi process sprockets compiling
72
+ test_files: []
73
+