Class: LittleGhost::TrustedPath

Inherits:
Data
  • Object
show all
Defined in:
lib/little_ghost/prompt_resolver.rb,
lib/little_ghost/prompt_resolver.rb

Overview

Marks a caller-supplied prompt directory as trusted application code. Construction resolves symbolic links immediately and rejects paths that are missing or are not directories.

Choosing prompt directories

ERB templates run as Ruby inside the current process. TrustedPath checks that a directory exists and resolves symbolic links; it cannot tell who may edit that directory. Create these values only from application-configured, non-user-writable roots, never from a request or model-selected path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ TrustedPath

Returns a new instance of TrustedPath.



12
13
14
15
16
17
18
# File 'lib/little_ghost/prompt_resolver.rb', line 12

def initialize(path:)
  expanded = File.realpath(path)
  raise ArgumentError, "trusted template path must be a directory" unless File.directory?(expanded)
  super(path: expanded.freeze)
rescue Errno::ENOENT
  raise ArgumentError, "trusted template path must exist"
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



11
12
13
# File 'lib/little_ghost/prompt_resolver.rb', line 11

def path
  @path
end