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/javascripts")) ⇒ AssetChangeSet

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



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/hot_loader/asset_change_set.rb', line 8

def initialize(since:, path: ::Rails.root.join("app/assets/javascripts"))
  @since = since
  @path = path.to_s
  asset_glob = path.to_s + "/**/*.js*"
  @changed_files = Dir.glob(asset_glob).select { |f| File.mtime(f) >= since }
  @changed_file_names = changed_files.map { |f| f.split("/").last }
  @changed_asset_contents = changed_files.map do |f|
    logical_path = f.sub(path.to_s, "").sub(/^\//, '')
    ::Rails.application.assets[logical_path].to_s
  end
end

Instance Attribute Details

#changed_asset_contentsObject (readonly)

Returns the value of attribute changed_asset_contents.



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

def changed_asset_contents
  @changed_asset_contents
end

#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)


20
21
22
# File 'lib/hot_loader/asset_change_set.rb', line 20

def any?
  changed_files.any?
end

#as_json(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/hot_loader/asset_change_set.rb', line 24

def as_json(options={})
  {
    since: since,
    path: path,
    changed_file_names: changed_file_names,
    changed_asset_contents: changed_asset_contents,
  }
end