Class: AppArchetype::Template::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/app_archetype/template/source.rb

Overview

Source is an in memory representation of a template source

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Source

Creates a templatte source from path and initializes file array.

Parameters:



12
13
14
15
# File 'lib/app_archetype/template/source.rb', line 12

def initialize(path)
  @path = path
  @files = []
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



5
6
7
# File 'lib/app_archetype/template/source.rb', line 5

def files
  @files
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/app_archetype/template/source.rb', line 5

def path
  @path
end

Instance Method Details

#exist?Boolean

Evaluates whether template source still exists.

Returns:

  • (Boolean)


34
35
36
# File 'lib/app_archetype/template/source.rb', line 34

def exist?
  File.exist?(@path)
end

#loadObject

Loads template files into memory. Will raise a RuntimeError if by the time we’re loading the source no longer exists.



21
22
23
24
25
26
27
# File 'lib/app_archetype/template/source.rb', line 21

def load
  raise 'template source does not exist' unless exist?

  Dir.glob(File.join(@path, '**', '*')).each do |file|
    @files << file
  end
end