Module: Pathtree::Dsl
- Included in:
- Trunk
- Defined in:
- lib/pathtree/dsl.rb
Overview
DSL for constructing path tree
Instance Attribute Summary collapse
-
#names ⇒ Object
readonly
Returns the value of attribute names.
Class Method Summary collapse
Instance Method Summary collapse
-
#directory(name, path = nil, &block) ⇒ Object
(also: #dir)
Grows directory branch from the branch.
-
#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.
Instance Attribute Details
#names ⇒ Object (readonly)
Returns the value of attribute names.
6 7 8 |
# File 'lib/pathtree/dsl.rb', line 6 def names @names end |
Class Method Details
.extend(path) ⇒ Object
34 35 36 37 38 |
# File 'lib/pathtree/dsl.rb', line 34 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.
24 25 26 27 28 29 30 |
# File 'lib/pathtree/dsl.rb', line 24 def directory(name, path = nil, &block) check_name(name) path = normalize(path, name:).then { nest(_1) } .then { Dsl.extend(_1) } .tap { _1.instance_eval(&block) if block } sprout(name:, 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
pathisnil,nameis used instead. -
If
pathis aProc, givenameto it. -
Otherwise,
pathitself is used.
15 16 17 18 19 |
# File 'lib/pathtree/dsl.rb', line 15 def file(name, path = nil) check_name(name) path = normalize(path, name:).then { nest(_1) } sprout(name:, path:) end |