Class: Pakyow::Generator
- Inherits:
-
Object
- Object
- Pakyow::Generator
- Includes:
- Common, Support::Hookable
- Defined in:
- lib/pakyow/generator.rb
Overview
Base class for generators.
Direct Known Subclasses
Defined Under Namespace
Modules: Common Classes: File, Processor
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
- #generate(destination_path, options) ⇒ Object
-
#initialize(source_path) ⇒ Generator
constructor
A new instance of Generator.
- #run(command, message:) ⇒ Object
Methods included from Common
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
#files ⇒ Object (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, ) @destination_path = destination_path performing :generate do FileUtils.mkdir_p(destination_path) @files.each do |file| file.generate(destination_path, ) 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: ).run( "cd #{@destination_path} && #{command}" ) end |