Class: JRubyEnginize::Generator
- Inherits:
-
Object
- Object
- JRubyEnginize::Generator
- Defined in:
- lib/generator.rb
Overview
Code for generating a directory tree created from a shared and a template specific set of template files.
Instance Attribute Summary collapse
-
#dryrun ⇒ Object
readonly
Returns the value of attribute dryrun.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Class Method Summary collapse
-
.templates ⇒ Object
Returns an Array with the available template names.
Instance Method Summary collapse
-
#initialize(email, path, template, options = {}) ⇒ Generator
constructor
Constructor of the generator needing at least email, path and template to run.
-
#run ⇒ Object
Runs the generator.
Constructor Details
#initialize(email, path, template, options = {}) ⇒ Generator
Constructor of the generator needing at least email, path and template to run.
Parameters:
-
Mail address of the Google AppEngine account to publish with
- path
-
Path of the directory to create
- template
-
Name of the set of templates to generate from
- options
-
Additional options
Options:
- :name
-
Optional app name defaulting to name of directory
- :dryrun
-
Flag to enable
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generator.rb', line 33 def initialize(email, path, template, = {}) @email = email @path = path @template = template = .dup @name = .delete(:name) @name = File.basename(path) if @name.nil? or @name.empty? @dryrun = .delete(:dryrun) raise ArgumentError, "Unknown option(s) #{.keys.join(', ')}" unless .empty? end |
Instance Attribute Details
#dryrun ⇒ Object (readonly)
Returns the value of attribute dryrun.
16 17 18 |
# File 'lib/generator.rb', line 16 def dryrun @dryrun end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
16 17 18 |
# File 'lib/generator.rb', line 16 def email @email end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/generator.rb', line 16 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/generator.rb', line 16 def path @path end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
16 17 18 |
# File 'lib/generator.rb', line 16 def template @template end |
Class Method Details
.templates ⇒ Object
Returns an Array with the available template names.
90 91 92 93 |
# File 'lib/generator.rb', line 90 def self.templates return Dir[File.join(Generator::templates_directory, '*')].collect { |path| (name = File.basename(path)) == 'shared' ? nil : name }.compact end |
Instance Method Details
#run ⇒ Object
Runs the generator. Starts with setting up a map of files to create and overriding shared ones with template specific stuff. Runs through the collected files and calls process_file to render new files in the target path.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/generator.rb', line 53 def run templatesdir = Generator::templates_directory shareddir = File.join(templatesdir, 'shared') templatedir = File.join(templatesdir, template) raise ArgumentError, 'Missing shared templates' unless File.stat(shareddir).directory? raise ArgumentError, "Template \"#{template}\" missing" unless File.stat(templatedir).directory? if dryrun puts "Dry run which would generate the following files from template \"#{template}\":" else puts "Generating files from template \"#{template}\"." end template_files(shareddir, templatedir).each do |key, path| target = File.join(self.path, key) if dryrun puts " Creating \"#{target}\" from template\n file \"#{path}\"" else process_file(path, target) end end if not dryrun puts "Done with directory \"#{self.path}\"." puts "\nYour next steps:\n cd #{self.path}\n\n sudo rake template:gems" puts "\n rake\n rake --tasks" puts "\n rake appengine:run # First call may fail: Just retry!" puts "\n rake appengine:deploy" end end |