Class: ProjectTemplater
- Inherits:
-
Object
- Object
- ProjectTemplater
- Defined in:
- lib/project_templater.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(template) ⇒ ProjectTemplater
constructor
A new instance of ProjectTemplater.
- #run(base_dir) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(template) ⇒ ProjectTemplater
Returns a new instance of ProjectTemplater.
12 13 14 15 |
# File 'lib/project_templater.rb', line 12 def initialize(template) @template = template puts "That generator doesn't exist." unless generator_exists? end |
Class Method Details
.generators ⇒ Object
21 22 23 24 25 26 |
# File 'lib/project_templater.rb', line 21 def self.generators Dir["lib/generators/*.rb"] .map { |g| g.split("/").last } .map { |g| g.gsub(".rb", "") } .select { |g| g != "generator" } end |
Instance Method Details
#run(base_dir) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/project_templater.rb', line 28 def run(base_dir) base_dir = Dir.pwd + "/" + (base_dir ||= "") class_name = @template.camel_case instance = Object::const_get(class_name).new(base_dir) instance.pre_install instance.run instance.post_install end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/project_templater.rb', line 17 def valid? generator_exists? end |