Coerce paths via settings rather than in class method

This commit is contained in:
Tim Riley 2019-01-29 15:50:36 +11:00
parent 6958014a6d
commit 571c8441e2
No known key found for this signature in database
GPG Key ID: 747ABA1282E88BC9
2 changed files with 12 additions and 7 deletions

View File

@ -24,7 +24,9 @@ module Dry
extend Dry::Configurable
setting :paths
setting :paths do |paths|
Array(paths).map { |path| Path[path] }
end
setting :layout, false
setting :layouts_dir, "layouts".freeze
setting :template
@ -55,11 +57,6 @@ module Dry
end
end
# @api public
def self.paths
Array(config.paths).map { |path| Path.new(path) }
end
# @api private
def self.layout_path
File.join(config.layouts_dir, config.layout)
@ -84,7 +81,7 @@ module Dry
def self.renderer(format)
fetch_or_store(:renderer, config, format) {
Renderer.new(
paths,
config.paths,
format: format,
engine_mapping: config.renderer_engine_mapping,
**config.renderer_options,

View File

@ -9,6 +9,14 @@ module Dry
attr_reader :dir, :root
def self.[](path)
if path.is_a?(self)
path
else
new(path)
end
end
def initialize(dir, root: dir)
@dir = Pathname(dir)
@root = root