Class: EacRubyUtils::Templates::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/templates/directory.rb

Defined Under Namespace

Classes: TemplateNode

Constant Summary collapse

TEMPLATE_EXTNAME =
'.template'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Directory

Returns a new instance of Directory.


12
13
14
# File 'lib/eac_ruby_utils/templates/directory.rb', line 12

def initialize(path)
  @path = path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path


10
11
12
# File 'lib/eac_ruby_utils/templates/directory.rb', line 10

def path
  @path
end

Instance Method Details

#apply(variables_source, directory) ⇒ Object


16
17
18
# File 'lib/eac_ruby_utils/templates/directory.rb', line 16

def apply(variables_source, directory)
  TemplateNode.new(self, '.', directory, variables_source).apply
end

#child(subpath) ⇒ Object


20
21
22
23
24
25
26
# File 'lib/eac_ruby_utils/templates/directory.rb', line 20

def child(subpath)
  child_path = ::File.join(path, subpath)
  return ::EacRubyUtils::Templates::File.new(child_path) if ::File.file?(child_path)
  return ::EacRubyUtils::Templates::Directory.new(child_path) if ::File.directory?(child_path)

  raise "Child \"#{subpath}\" from \"#{path}\" not found"
end

#childrenObject


28
29
30
31
32
# File 'lib/eac_ruby_utils/templates/directory.rb', line 28

def children
  path.children.map do |path_child|
    child(path_child.basename.to_path)
  end
end