class React::Rails::HotLoader::AssetChangeSet
Attributes
changed_file_names[R]
changed_files[R]
path[R]
since[R]
Public Class Methods
new(since:, path: ::Rails.root.join("app/assets"))
click to toggle source
initialize with a path and time to find files which changed since that time
# File lib/hot_loader/asset_change_set.rb, line 14 def initialize(since:, path: ::Rails.root.join("app/assets")) @since = since @path = path.to_s asset_glob = File.join(path, AssetChangeSet.asset_glob) @changed_files = Dir.glob(asset_glob).select { |f| File.mtime(f) >= since }.uniq @changed_file_names = changed_files.map { |f| File.basename(f) } end
Public Instance Methods
any?()
click to toggle source
# File lib/hot_loader/asset_change_set.rb, line 26 def any? changed_files.any? end
as_json(options={})
click to toggle source
# File lib/hot_loader/asset_change_set.rb, line 30 def as_json(options={}) { since: since, path: path, changed_file_names: changed_file_names, changed_asset_contents: changed_asset_contents, } end
bankrupt?()
click to toggle source
# File lib/hot_loader/asset_change_set.rb, line 22 def bankrupt? changed_files.length >= self.class.bankruptcy_count end
changed_asset_contents()
click to toggle source
# File lib/hot_loader/asset_change_set.rb, line 39 def changed_asset_contents @changed_asset_contents ||= changed_files.map do |f| logical_path = to_logical_path(f) asset = ::Rails.application.assets[logical_path] asset.to_s end end
Private Instance Methods
to_logical_path(asset_path)
click to toggle source
# File lib/hot_loader/asset_change_set.rb, line 49 def to_logical_path(asset_path) asset_path .sub(@path, "") # remove the basepath .sub(/(javascripts|stylesheets)\//, '') # remove the asset directory .sub(/^\//, '') # remove any leading / .sub(/\.js.*/, '.js') # uniform .js for js .sub(/\.[sac]{1,2}ss.*/, '.css') # uniform .css for styles end