Class: AnimateIt::AssetManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/animate_it/asset_manifest.rb

Overview

Validates source inputs that a host application needs to reproduce its compositions. Media remains owned by the host; the gem only defines the manifest contract and checksum/provenance preflight.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: Rails.root, path: nil) ⇒ AssetManifest

Returns a new instance of AssetManifest.



18
19
20
21
# File 'lib/animate_it/asset_manifest.rb', line 18

def initialize(root: Rails.root, path: nil)
  @root = Pathname(root).expand_path
  @path = Pathname(path || @root.join("config/animate_it_assets.yml"))
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/animate_it/asset_manifest.rb', line 16

def path
  @path
end

#rootObject (readonly)

Returns the value of attribute root.



16
17
18
# File 'lib/animate_it/asset_manifest.rb', line 16

def root
  @root
end

Instance Method Details

#validateObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/animate_it/asset_manifest.rb', line 23

def validate
  manifest = load_manifest
  assets = manifest.fetch("assets")
  errors = []
  errors << "manifest version must be 1" unless manifest["version"] == 1
  errors.concat(validate_assets(assets))
  Result.new(assets.size, errors)
rescue Errno::ENOENT
  Result.new(0, ["asset manifest not found: #{path}"])
rescue KeyError, Psych::Exception => e
  Result.new(0, ["invalid asset manifest #{path}: #{e.message}"])
end

#validate!Object

Raises:



36
37
38
39
40
41
# File 'lib/animate_it/asset_manifest.rb', line 36

def validate!
  result = validate
  return result if result.success?

  raise Error, "AnimateIt asset preflight failed:\n- #{result.errors.join("\n- ")}"
end