Class: Pakyow::Generator

Inherits:
Object
  • Object
show all
Includes:
Common, Support::Hookable
Defined in:
lib/pakyow/generator.rb

Overview

Base class for generators.

Direct Known Subclasses

Pakyow::Generators::Project

Defined Under Namespace

Modules: Common Classes: File, Processor

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#dot

Constructor Details

#initialize(source_path) ⇒ Generator

Returns a new instance of Generator.



32
33
34
35
36
37
38
# File 'lib/pakyow/generator.rb', line 32

def initialize(source_path)
  @files = Dir.glob(::File.join(source_path, "**/*")).reject { |path|
    ::File.directory?(path)
  }.map { |path|
    File.new(path, source_path, context: self)
  }
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



30
31
32
# File 'lib/pakyow/generator.rb', line 30

def files
  @files
end

Instance Method Details

#generate(destination_path, options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pakyow/generator.rb', line 40

def generate(destination_path, options)
  @destination_path = destination_path

  performing :generate do
    FileUtils.mkdir_p(destination_path)

    @files.each do |file|
      file.generate(destination_path, options)
    end
  end
end

#run(command, message:) ⇒ Object



52
53
54
55
56
# File 'lib/pakyow/generator.rb', line 52

def run(command, message:)
  Support::CLI::Runner.new(message: message).run(
    "cd #{@destination_path} && #{command}"
  )
end