class Manifester::Manifest

Public Class Methods

new(manifester) click to toggle source
# File lib/manifester/manifest.rb, line 7
def initialize(manifester)
  @manifester = manifester
end

Public Instance Methods

lookup(name, pack_type = {}) click to toggle source

Computes the relative path for a given Manifester asset using manifest.json. If no asset is found, returns nil.

Example:

Manifester.manifest.lookup('calendar.js') # => "/packs/calendar-1016838bab065ae1e122.js"
# File lib/manifester/manifest.rb, line 33
def lookup(name, pack_type = {})
  find(full_pack_name(name, pack_type[:type]))
end
lookup!(name, pack_type = {}) click to toggle source

Like lookup, except that if no asset is found, raises a Manifester::Manifest::MissingEntryError.

# File lib/manifester/manifest.rb, line 38
def lookup!(name, pack_type = {})
  lookup(name, pack_type) || handle_missing_entry(name, pack_type)
end
lookup_manifest_with_chunks(name, pack_type = {}) click to toggle source
# File lib/manifester/manifest.rb, line 15
def lookup_manifest_with_chunks(name, pack_type = {})
  manifest_pack_type = manifest_type(pack_type[:type])
  manifest_pack_name = manifest_name(name, manifest_pack_type)
  find("entrypoints")[manifest_pack_name]["assets"][manifest_pack_type]
rescue NoMethodError
  nil
end
lookup_manifest_with_chunks!(name, pack_type = {}) click to toggle source
# File lib/manifester/manifest.rb, line 23
def lookup_manifest_with_chunks!(name, pack_type = {})
  lookup_manifest_with_chunks(name, pack_type) || handle_missing_entry(name, pack_type)
end
refresh() click to toggle source
# File lib/manifester/manifest.rb, line 11
def refresh
  @data = load
end

Private Instance Methods

data() click to toggle source
# File lib/manifester/manifest.rb, line 43
def data
  if config.cache_manifest?
    @data ||= load
  else
    refresh
  end
end
find(name) click to toggle source
# File lib/manifester/manifest.rb, line 51
def find(name)
  data[name.to_s].presence
end
full_pack_name(name, pack_type) click to toggle source
# File lib/manifester/manifest.rb, line 55
def full_pack_name(name, pack_type)
  return name unless File.extname(name.to_s).empty?
  "#{name}.#{manifest_type(pack_type)}"
end
handle_missing_entry(name, pack_type) click to toggle source
# File lib/manifester/manifest.rb, line 60
def handle_missing_entry(name, pack_type)
  raise Manifester::Manifest::MissingEntryError, missing_file_from_manifest_error(full_pack_name(name, pack_type[:type]))
end
load() click to toggle source
# File lib/manifester/manifest.rb, line 64
def load
  if config.public_manifest_path.exist?
    JSON.parse config.public_manifest_path.read
  else
    {}
  end
end
manifest_name(name, pack_type) click to toggle source

The `manifest_name` method strips of the file extension of the name, because in the manifest hash the entrypoints are defined by their pack name without the extension. When the user provides a name with a file extension, we want to try to strip it off.

# File lib/manifester/manifest.rb, line 75
def manifest_name(name, pack_type)
  return name if File.extname(name.to_s).empty?
  File.basename(name, ".#{pack_type}")
end
manifest_type(pack_type) click to toggle source
# File lib/manifester/manifest.rb, line 80
def manifest_type(pack_type)
  case pack_type
  when :javascript then "js"
  when :stylesheet then "css"
  else pack_type.to_s
  end
end
missing_file_from_manifest_error(bundle_name) click to toggle source
# File lib/manifester/manifest.rb, line 88
    def missing_file_from_manifest_error(bundle_name)
      <<-MSG
Manifester can't find #{bundle_name} in #{config.public_manifest_path}.
Your manifest contains:
#{JSON.pretty_generate(@data)}
      MSG
    end