class Pathtree::Dsl

Public Class Methods

new(working_directory: Pathname.pwd) click to toggle source

See also Pathtree::Dsl.read.

# File lib/pathtree.rb, line 60
def initialize(working_directory: Pathname.pwd)
  @working_directory = Pathtree.new(working_directory)
end
read(file_path, working_directory: Pathname.pwd) click to toggle source
# File lib/pathtree.rb, line 53
def self.read(file_path, working_directory: Pathname.pwd)
  new(working_directory: working_directory)
    .tap { _1.send(:read, file_path) }
    .instance_variable_get(:@working_directory)
end

Public Instance Methods

dir(name, path = nil, &block)
Alias for: directory
directory(name, path = nil, &block) click to toggle source
# File lib/pathtree.rb, line 77
def directory(name, path = nil, &block)
  path = path.directory_path(name: name)

  # NOTE: Temporal variable is needed
  # since define_singleton_method's block is evaluated using instance_eval
  # which is same as define_method.
  working_directory = @working_directory / path

  @working_directory.define_singleton_method(name) do
    Dsl.new(working_directory: working_directory)
       .tap { _1.instance_eval(&block) if block_given? }
       .instance_variable_get(:@working_directory)
  end
end
Also aliased as: dir
file(name, path = nil) click to toggle source
# File lib/pathtree.rb, line 66
def file(name, path = nil)
  path = path.file_path(name: name)

  # NOTE: Temporal variable is needed
  # since define_singleton_method's block is evaluated using instance_eval
  # which is same as define_method.
  working_directory = @working_directory

  @working_directory.define_singleton_method(name) { working_directory / path }
end

Private Instance Methods

read(file_path) click to toggle source
# File lib/pathtree.rb, line 98
def read(file_path)
  instance_eval File.read(file_path)
end