Class: Wellcar::Templates::Base

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/wellcar/templates/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/wellcar/templates/base.rb', line 6

def initialize(file_path)
  @file_path = file_path
  @before_write = []
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/wellcar/templates/base.rb', line 17

def exist?
  File.exist? file_path
end

#renderObject



21
22
23
# File 'lib/wellcar/templates/base.rb', line 21

def render
  ERB.new(template).result(binding)
end

#writeObject



11
12
13
14
15
# File 'lib/wellcar/templates/base.rb', line 11

def write
  @before_write.each {|procedure| procedure.call }

  File.open(file_path, 'w') {|file| file.write render }
end