lib/hanami/assets.rb in hanami-assets-2.1.0.rc2 vs lib/hanami/assets.rb in hanami-assets-2.1.0.rc3
- old
+ new
@@ -1,8 +1,9 @@
# frozen_string_literal: true
require "json"
+require "pathname"
require "zeitwerk"
module Hanami
# Assets management for Ruby web applications
#
@@ -28,21 +29,26 @@
require_relative "assets/version"
require_relative "assets/errors"
# @api private
# @since 2.1.0
- SEPARATOR = "/"
- private_constant :SEPARATOR
+ MANIFEST_PATH = "assets.json"
+ private_constant :MANIFEST_PATH
# @api private
# @since 2.1.0
attr_reader :config
+ # @api private
+ # @since 2.1.0
+ attr_reader :root
+
# @api public
# @since 2.1.0
- def initialize(config:)
+ def initialize(config:, root:)
@config = config
+ @root = Pathname(root)
end
# Returns the asset at the given path.
#
# @return [Hanami::Assets::Asset] the asset
@@ -90,17 +96,15 @@
private
def manifest
return @manifest if instance_variable_defined?(:@manifest)
- unless config.manifest_path
- raise ConfigError, "no manifest_path configured"
- end
+ full_manifest_path = root.join(MANIFEST_PATH)
- unless File.exist?(config.manifest_path)
- raise ManifestMissingError.new(config.manifest_path)
+ unless full_manifest_path.exist?
+ raise ManifestMissingError.new(full_manifest_path.to_s)
end
- @manifest = JSON.parse(File.read(config.manifest_path))
+ @manifest = JSON.parse(File.read(full_manifest_path))
end
end
end