Class: Zui::Generator
- Inherits:
-
Object
- Object
- Zui::Generator
- Defined in:
- lib/zui/generator.rb
Constant Summary collapse
- DEFAULT_ASSETS =
File.("generator_assets", __dir__)
- RELEASE_ICONS =
%w[ruby.png ruby.icns ruby.ico].freeze
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(path:, name: nil) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(path:, name: nil) ⇒ Generator
Returns a new instance of Generator.
10 11 12 13 |
# File 'lib/zui/generator.rb', line 10 def initialize(path:, name: nil) @path = File.(path) @name = display_name(name || File.basename(@path)) end |
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zui/generator.rb', line 15 def create raise ArgumentError, "destination already exists: #{@path}" if File.exist?(@path) created = true FileUtils.mkdir_p(File.join(@path, "components")) File.write(File.join(@path, "main.rb"), main_program) File.write(File.join(@path, "Gemfile"), gemfile) File.write(File.join(@path, "components", "welcome.rb"), welcome_component) File.write(File.join(@path, "config.rb"), distribution_config) assets = File.join(@path, "assets") FileUtils.mkdir_p(assets) RELEASE_ICONS.each { |name| FileUtils.cp(File.join(DEFAULT_ASSETS, name), assets) } File.write(File.join(@path, "README.md"), readme) @path rescue StandardError FileUtils.remove_entry(@path) if created && File.directory?(@path) raise end |