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 45 |
# File 'lib/rack/pack/package.rb', line 40 def compile @size = source_files.size compiled = source_files.map(&:read).join compiled = compress(compiled) if compress? compiled.strip end |
#compress(source) ⇒ Object
47 48 49 |
# File 'lib/rack/pack/package.rb', line 47 def compress(source) source end |
#compress? ⇒ Boolean
60 61 62 |
# File 'lib/rack/pack/package.rb', line 60 def compress? Pack.production? || Pack. && Pack.[:always_compress] end |
#source_files ⇒ Object
56 57 58 |
# File 'lib/rack/pack/package.rb', line 56 def source_files @source_files ||= glob? ? Pathname.glob(@from) : @from end |
#stale? ⇒ Boolean
51 52 53 54 |
# File 'lib/rack/pack/package.rb', line 51 def stale? @source_files = nil source_files? && (file_missing? || source_files_added_or_removed? || 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 |