Class: Gluey::Dependencies::TextsBundle
- Inherits:
-
SingleFile
- Object
- SingleFile
- Gluey::Dependencies::TextsBundle
- Defined in:
- lib/gluey/workshop/dependencies/texts_bundle.rb
Constant Summary collapse
- JS_ESCAPE_MAP =
{ '\\' => '\\\\', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" }
Instance Attribute Summary
Attributes inherited from SingleFile
Instance Method Summary collapse
- #actualize ⇒ Object
- #changed? ⇒ Boolean
-
#initialize(dir, logical_path, context) ⇒ TextsBundle
constructor
A new instance of TextsBundle.
- #mark ⇒ Object
Methods inherited from SingleFile
Constructor Details
#initialize(dir, logical_path, context) ⇒ TextsBundle
Returns a new instance of TextsBundle.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gluey/workshop/dependencies/texts_bundle.rb', line 14 def initialize(dir, logical_path, context) tmp_dir = "#{context.cache_path}/.texts_bundle" Dir.mkdir tmp_dir unless Dir.exists? tmp_dir @cache_path = "#{tmp_dir}/#{logical_path.gsub '/', '-'}" Dir.mkdir @cache_path unless Dir.exists? @cache_path @dir_dep = ::Gluey::Dependencies::Directory.new(dir, '**/*') @dependencies = [] super "#{@cache_path}.texts_bundle" end |
Instance Method Details
#actualize ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gluey/workshop/dependencies/texts_bundle.rb', line 33 def actualize # remove deleted files @dependencies.delete_if{|dep| !dep.exists? } # add new files new_files = (@dir_dep.files_list - @dependencies.map(&:file)).map do |f| text_name = f[/#{@dir_dep.file}\/(.+)$/, 1] ::Gluey::Dependencies::SingleFile.new f, text_name: text_name end @dependencies.concat new_files @dir_dep.actualize @dependencies.each{|dep| dep.actualize if dep.changed? } write_bundle @mtime = File.mtime(@file).to_i self end |
#changed? ⇒ Boolean
25 26 27 |
# File 'lib/gluey/workshop/dependencies/texts_bundle.rb', line 25 def changed? @dependencies.any?{|d| d.changed?} || @dir_dep.changed? || (File.mtime(@file).to_i != @mtime rescue true) end |
#mark ⇒ Object
29 30 31 |
# File 'lib/gluey/workshop/dependencies/texts_bundle.rb', line 29 def mark @dependencies.map(&:mark).join end |