Class: ActionView::Helpers::AssetTagHelper::AssetCollection

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Memoizable
Defined in:
lib/action_view/helpers/asset_tag_helper.rb

Direct Known Subclasses

JavaScriptSources, StylesheetSources

Constant Summary collapse

Cache =
{}
CacheGuard =
Mutex.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, controller, sources, recursive) ⇒ AssetCollection

Returns a new instance of AssetCollection.



706
707
708
709
710
711
712
713
# File 'lib/action_view/helpers/asset_tag_helper.rb', line 706

def initialize(template, controller, sources, recursive)
  # NOTE: The template arg is temporarily needed for a legacy plugin
  # hook. See NOTE under AssetTag#initialize for more details
  @template = template
  @controller = controller
  @sources = sources
  @recursive = recursive
end

Class Method Details

.create(template, controller, sources, recursive) ⇒ Object



699
700
701
702
703
704
# File 'lib/action_view/helpers/asset_tag_helper.rb', line 699

def self.create(template, controller, sources, recursive)
  CacheGuard.synchronize do
    key = [self, sources, recursive]
    Cache[key] ||= new(template, controller, sources, recursive).freeze
  end
end

Instance Method Details

#write_asset_file_contents(joined_asset_path) ⇒ Object



715
716
717
718
719
720
# File 'lib/action_view/helpers/asset_tag_helper.rb', line 715

def write_asset_file_contents(joined_asset_path)
  FileUtils.mkdir_p(File.dirname(joined_asset_path))
  File.open(joined_asset_path, "w+") { |cache| cache.write(joined_contents) }
  mt = latest_mtime
  File.utime(mt, mt, joined_asset_path)
end