Class: UnifiedAssets::Builder
- Inherits:
-
Object
- Object
- UnifiedAssets::Builder
- Defined in:
- lib/unified_assets/builder.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#minified_file_mtime ⇒ Object
readonly
Returns the value of attribute minified_file_mtime.
-
#minified_file_name ⇒ Object
readonly
Returns the value of attribute minified_file_name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#unified_file_mtime ⇒ Object
readonly
Returns the value of attribute unified_file_mtime.
-
#unified_file_name ⇒ Object
readonly
Returns the value of attribute unified_file_name.
Instance Method Summary collapse
- #build ⇒ Object
- #debug(msg, options = {}) ⇒ Object
-
#initialize(files, unified_file_name, options = {}) ⇒ Builder
constructor
A new instance of Builder.
- #minified_file_missing? ⇒ Boolean
- #minifying? ⇒ Boolean
- #rebuild? ⇒ Boolean
- #rebuild_reason ⇒ Object
- #unified_file_missing? ⇒ Boolean
Constructor Details
#initialize(files, unified_file_name, options = {}) ⇒ Builder
Returns a new instance of Builder.
11 12 13 14 15 16 17 18 |
# File 'lib/unified_assets/builder.rb', line 11 def initialize(files, unified_file_name, = {}) @options = @files = Array(files) @unified_file_name = unified_file_name @unified_file_mtime = File.stat(unified_file_name).mtime if File.exists?(unified_file_name) @minified_file_name = Minifier.minified_name(unified_file_name) if @minified_file_mtime = File.stat(minified_file_name).mtime if && File.exists?(minified_file_name) end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
4 5 6 |
# File 'lib/unified_assets/builder.rb', line 4 def files @files end |
#minified_file_mtime ⇒ Object (readonly)
Returns the value of attribute minified_file_mtime.
8 9 10 |
# File 'lib/unified_assets/builder.rb', line 8 def minified_file_mtime @minified_file_mtime end |
#minified_file_name ⇒ Object (readonly)
Returns the value of attribute minified_file_name.
7 8 9 |
# File 'lib/unified_assets/builder.rb', line 7 def minified_file_name @minified_file_name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/unified_assets/builder.rb', line 9 def @options end |
#unified_file_mtime ⇒ Object (readonly)
Returns the value of attribute unified_file_mtime.
6 7 8 |
# File 'lib/unified_assets/builder.rb', line 6 def unified_file_mtime @unified_file_mtime end |
#unified_file_name ⇒ Object (readonly)
Returns the value of attribute unified_file_name.
5 6 7 |
# File 'lib/unified_assets/builder.rb', line 5 def unified_file_name @unified_file_name end |
Instance Method Details
#build ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/unified_assets/builder.rb', line 54 def build if rebuild? debug("**** REGENERATING #{unified_file_name} BECAUSE #{rebuild_reason} ****", ) File.open(unified_file_name, 'w') do |uf| files.each do |filename| debug("**** RENDERING #{filename}") uf << IO.read(filename) end end Minifier.minify(unified_file_name) if end end |
#debug(msg, options = {}) ⇒ Object
67 68 69 |
# File 'lib/unified_assets/builder.rb', line 67 def debug(msg, = {}) puts msg if [:debug] end |
#minified_file_missing? ⇒ Boolean
24 25 26 |
# File 'lib/unified_assets/builder.rb', line 24 def minified_file_missing? && minified_file_mtime.nil? end |
#minifying? ⇒ Boolean
28 29 30 |
# File 'lib/unified_assets/builder.rb', line 28 def !![:minify] && Minifier.enabled?(unified_file_name) end |
#rebuild? ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/unified_assets/builder.rb', line 32 def rebuild? if @rebuild_because.nil? @rebuild_because = [] @rebuild_because << "UNIFIED FILE IS MISSING" if unified_file_missing? @rebuild_because << "MINIFIED FILE IS MISSING" if minified_file_missing? @rebuild_because << "MINIFIED FILE IS OUT OF DATE" if && !minified_file_missing? && !unified_file_missing? && (minified_file_mtime < unified_file_mtime) unless unified_file_missing? files.each do |name| file_mtime = File.stat(name).mtime if (file_mtime > unified_file_mtime) @rebuild_because << "#{name} IS OUT OF DATE" end end end end !@rebuild_because.empty? end |
#rebuild_reason ⇒ Object
50 51 52 |
# File 'lib/unified_assets/builder.rb', line 50 def rebuild_reason @rebuild_because.join(', ') if rebuild? end |
#unified_file_missing? ⇒ Boolean
20 21 22 |
# File 'lib/unified_assets/builder.rb', line 20 def unified_file_missing? unified_file_mtime.nil? end |