Module: Pathtree::Dsl

Included in:
Trunk
Defined in:
lib/pathtree/dsl.rb

Overview

DSL for constructing path tree

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



8
9
10
# File 'lib/pathtree/dsl.rb', line 8

def names
  @names
end

Class Method Details

.extend(path) ⇒ Object



36
37
38
39
40
# File 'lib/pathtree/dsl.rb', line 36

def self.extend(path)
  path.instance_variable_set(:@names, [])
  path.extend(Dsl)
  path
end

Instance Method Details

#directory(name, path = nil, &block) ⇒ Object Also known as: dir

Grows directory branch from the branch. See also Pathtree::Dsl#file method. This method has optional block, which represents nested file structure.



26
27
28
29
30
31
32
# File 'lib/pathtree/dsl.rb', line 26

def directory(name, path = nil, &block)
  check_name(name)
  path = normalize(path, name: name).then { nest(_1) }
                                    .then { Dsl.extend(_1) }
                                    .tap { _1.instance_eval(&block) if block }
  sprout(name: name, path: path)
end

#file(name, path = nil) ⇒ Object

Grows file leaf from the branch; The path at the point where this method is called attempts to create an instance method that returns the path with the name.

  • If path is nil, name is used instead.

  • If path is a Proc, give name to it.

  • Otherwise, path itself is used.



17
18
19
20
21
# File 'lib/pathtree/dsl.rb', line 17

def file(name, path = nil)
  check_name(name)
  path = normalize(path, name: name).then { nest(_1) }
  sprout(name: name, path: path)
end