Class: MultiSync::ManifestSource

Inherits:
Source
  • Object
show all
Defined in:
lib/multi_sync/sources/manifest_source.rb

Instance Method Summary collapse

Methods included from MultiSync::Mixins::LogHelper

#class_name

Instance Method Details

#filesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/multi_sync/sources/manifest_source.rb', line 8

def files
  files = []
  manifest_hash = {}

  # ::ActionView::Base has a shortcut to the manifest file
  # otherwise lets hunt down that manifest file!
  if defined?(::ActionView::Base) && ::ActionView::Base.respond_to?(:assets_manifest)
    manifest_hash = ::ActionView::Base.assets_manifest.files
  else
    manifest_path = locate_manifest(source_dir)
    manifest_hash = parse_manifest(manifest_path)
  end

  # create a local_resource from each file
  # making sure to skip any that do not match the include/exclude patterns
  manifest_hash.lazily.each { |key, value|
    path = source_dir + key
    next if !path.fnmatch?(include.to_s) || path.fnmatch?(exclude.to_s || '')
    file = path_to_local_resource(path, mtime: value['mtime'], digest: value['digest'], content_length: value['size'])
    files << file
  }

  files
end