Class: Tony::Generator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Generator

Returns a new instance of Generator.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(&block)
  yield self
end

Instance Attribute Details

#combinationObject

Returns the value of attribute combination.



5
6
7
# File 'lib/tony/generator.rb', line 5

def combination
  @combination
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/tony/generator.rb', line 5

def description
  @description
end

#filesObject

Returns the value of attribute files.



5
6
7
# File 'lib/tony/generator.rb', line 5

def files
  @files
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tony/generator.rb', line 5

def name
  @name
end

Instance Method Details

#generateObject



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

def generate
  files.each do |path, contents|
    FileUtils.mkdir_p(File.dirname(path))
    puts "create #{path}" unless File.exist?(path)
    puts "append #{path}" if File.exist?(path)
    File.open(path, 'a') do |file|
      file.puts(contents)
    end
  end
end