Class: React::Rails::HotLoader::AssetChangeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/hot_loader/asset_change_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(since:, path: ::Rails.root.join("app/assets")) ⇒ AssetChangeSet

initialize with a path and time to find files which changed since that time



14
15
16
17
18
19
20
# 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

Instance Attribute Details

#changed_file_namesObject (readonly)

Returns the value of attribute changed_file_names.



5
6
7
# File 'lib/hot_loader/asset_change_set.rb', line 5

def changed_file_names
  @changed_file_names
end

#changed_filesObject (readonly)

Returns the value of attribute changed_files.



5
6
7
# File 'lib/hot_loader/asset_change_set.rb', line 5

def changed_files
  @changed_files
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/hot_loader/asset_change_set.rb', line 5

def path
  @path
end

#sinceObject (readonly)

Returns the value of attribute since.



5
6
7
# File 'lib/hot_loader/asset_change_set.rb', line 5

def since
  @since
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/hot_loader/asset_change_set.rb', line 26

def any?
  changed_files.any?
end

#as_json(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# 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?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/hot_loader/asset_change_set.rb', line 22

def bankrupt?
  changed_files.length >= self.class.bankruptcy_count
end

#changed_asset_contentsObject



39
40
41
42
43
44
45
# 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