Class: Generator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/generator/base.rb

Constant Summary collapse

@@FILE_CHECKSUMS =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cache(file) ⇒ Object



43
44
45
# File 'lib/generator/base.rb', line 43

def self.cache(file)
  @@FILE_CHECKSUMS[file] = self.checksum(file)
end

.changed?(file) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/generator/base.rb', line 38

def self.changed?(file)
  return true unless @@FILE_CHECKSUMS.has_key? file
  @@FILE_CHECKSUMS[file] != self.checksum(file)
end

.checksum(file) ⇒ Object



34
35
36
# File 'lib/generator/base.rb', line 34

def self.checksum(file)
  Digest::MD5.hexdigest(File.read(file))
end

Instance Method Details

#compile(input) ⇒ Object



24
25
26
# File 'lib/generator/base.rb', line 24

def compile(input)
  input
end

#compile_file(input_file, *args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generator/base.rb', line 11

def compile_file(input_file, *args)
  return unless self.class.changed? (input_file)

  #if args[0] isset, it is a file, the output file
  if args.length > 0
    write(args[0], compile(File.read(input_file), *args))
  else
    compile(input_file, *args)
  end

  self.class.cache(input_file)
end

#generate(input_folder, output_folder) ⇒ Object



7
8
9
# File 'lib/generator/base.rb', line 7

def generate(input_folder, output_folder)

end

#write(file, content) ⇒ Object



28
29
30
31
32
# File 'lib/generator/base.rb', line 28

def write(file, content)
  File.open(file, "w") do |f|
    f.write content
  end
end