Class: JRubyEnginize::Generator

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, path, template, options = {}) ⇒ Generator

Constructor of the generator needing at least email, path and template to run.

Parameters:

email

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

Raises:

  • (ArgumentError)


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, options = {})
  @email = email
  @path = path
  @template = template

  options = options.dup

  @name = options.delete(:name)
  @name = File.basename(path) if @name.nil? or @name.empty?

  @dryrun = options.delete(:dryrun)

  raise ArgumentError, "Unknown option(s) #{options.keys.join(', ')}" unless options.empty?
end

Instance Attribute Details

#dryrunObject (readonly)

Returns the value of attribute dryrun.



16
17
18
# File 'lib/generator.rb', line 16

def dryrun
  @dryrun
end

#emailObject (readonly)

Returns the value of attribute email.



16
17
18
# File 'lib/generator.rb', line 16

def email
  @email
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/generator.rb', line 16

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/generator.rb', line 16

def path
  @path
end

#templateObject (readonly)

Returns the value of attribute template.



16
17
18
# File 'lib/generator.rb', line 16

def template
  @template
end

Class Method Details

.templatesObject

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

#runObject

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.

Raises:

  • (ArgumentError)


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