Class: EacTemplates::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_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.



11
12
13
# File 'lib/eac_templates/directory.rb', line 11

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.



9
10
11
# File 'lib/eac_templates/directory.rb', line 9

def path
  @path
end

Instance Method Details

#apply(variables_source, directory) ⇒ Object



15
16
17
# File 'lib/eac_templates/directory.rb', line 15

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

#child(subpath) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/eac_templates/directory.rb', line 19

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

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

#childrenObject



27
28
29
30
31
# File 'lib/eac_templates/directory.rb', line 27

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