Class: Rack::Pack::Package
- Inherits:
-
Object
- Object
- Rack::Pack::Package
- Defined in:
- lib/rack/pack/package.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
- #compile ⇒ Object
- #compress(source) ⇒ Object
- #compress? ⇒ Boolean
-
#initialize(output_file, source_files) ⇒ Package
constructor
A new instance of Package.
- #source_files ⇒ Object
- #stale? ⇒ Boolean
- #update ⇒ Object
Constructor Details
#initialize(output_file, source_files) ⇒ Package
Returns a new instance of Package.
24 25 26 27 28 29 30 31 |
# File 'lib/rack/pack/package.rb', line 24 def initialize(output_file, source_files) @file = to_pathname(output_file) @from = if source_files.is_a?(Array) source_files.map { |file| to_pathname(file) } else source_files.to_s end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
22 23 24 |
# File 'lib/rack/pack/package.rb', line 22 def file @file end |
Class Method Details
.[](file) ⇒ Object
16 17 18 19 |
# File 'lib/rack/pack/package.rb', line 16 def [](file) ext = ::File.extname(file.to_s).sub(/^\./, '').downcase mappings[ext] || self end |
.mappings ⇒ Object
7 8 9 |
# File 'lib/rack/pack/package.rb', line 7 def mappings @package_mappings ||= {} end |
.register(ext, package_class) ⇒ Object
11 12 13 14 |
# File 'lib/rack/pack/package.rb', line 11 def register(ext, package_class) ext = ext.to_s.sub(/^\./, '').downcase mappings[ext] = package_class end |
Instance Method Details
#compile ⇒ Object
40 41 42 43 44 |
# File 'lib/rack/pack/package.rb', line 40 def compile compiled = source_files.map(&:read).join compiled = compress(compiled) if compress? compiled.strip end |
#compress(source) ⇒ Object
46 47 48 |
# File 'lib/rack/pack/package.rb', line 46 def compress(source) source end |
#compress? ⇒ Boolean
59 60 61 |
# File 'lib/rack/pack/package.rb', line 59 def compress? Pack.production? || Pack. && Pack.[:always_compress] end |
#source_files ⇒ Object
55 56 57 |
# File 'lib/rack/pack/package.rb', line 55 def source_files @source_files ||= @from.is_a?(Array) ? @from : Pathname.glob(@from) end |
#stale? ⇒ Boolean
50 51 52 53 |
# File 'lib/rack/pack/package.rb', line 50 def stale? @source_files = nil source_files? && (file_missing? || source_files_newer?) end |
#update ⇒ Object
33 34 35 36 37 38 |
# File 'lib/rack/pack/package.rb', line 33 def update file.dirname.mkpath file.open('w') do |file| file << compile end end |