Class: Dry::View::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/view/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, options = {}) ⇒ Path

Returns a new instance of Path.



10
11
12
13
# File 'lib/dry/view/path.rb', line 10

def initialize(dir, options = {})
  @dir = Pathname(dir)
  @root = Pathname(options.fetch(:root, dir))
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



8
9
10
# File 'lib/dry/view/path.rb', line 8

def dir
  @dir
end

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/dry/view/path.rb', line 8

def root
  @root
end

Instance Method Details

#chdir(dirname) ⇒ Object



19
20
21
# File 'lib/dry/view/path.rb', line 19

def chdir(dirname)
  self.class.new(dir.join(dirname), root: root)
end

#lookup(name, format) ⇒ Object



15
16
17
# File 'lib/dry/view/path.rb', line 15

def lookup(name, format)
  template?(name, format) || template?("shared/#{name}", format) || !root? && chdir('..').lookup(name, format)
end

#to_sObject



23
24
25
# File 'lib/dry/view/path.rb', line 23

def to_s
  dir
end