Class: RStack::Generator
- Inherits:
-
Object
- Object
- RStack::Generator
- Defined in:
- lib/rstack/generator.rb
Instance Attribute Summary collapse
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#main_path ⇒ Object
readonly
Returns the value of attribute main_path.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pathized_project_name ⇒ Object
readonly
Returns the value of attribute pathized_project_name.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
-
#templates_path ⇒ Object
readonly
Returns the value of attribute templates_path.
Instance Method Summary collapse
- #author ⇒ Object
- #create_directories ⇒ Object
-
#initialize(project_name) ⇒ Generator
constructor
A new instance of Generator.
- #move_template(template_name, destination_path) ⇒ Object
- #paths ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(project_name) ⇒ Generator
Returns a new instance of Generator.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rstack/generator.rb', line 7 def initialize(project_name) @project_name = project_name.downcase @pathized_project_name = @project_name.underscore @module_name = @pathized_project_name.camelize @path = Pathname.new(@project_name). parts = @pathized_project_name.split("/") @main = parts.last + ".rb" @main_path = Pathname.new((parts - [parts.last]).join("/")) @templates_path = RStack.root.join('templates') end |
Instance Attribute Details
#main ⇒ Object (readonly)
Returns the value of attribute main.
4 5 6 |
# File 'lib/rstack/generator.rb', line 4 def main @main end |
#main_path ⇒ Object (readonly)
Returns the value of attribute main_path.
4 5 6 |
# File 'lib/rstack/generator.rb', line 4 def main_path @main_path end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
4 5 6 |
# File 'lib/rstack/generator.rb', line 4 def module_name @module_name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/rstack/generator.rb', line 4 def path @path end |
#pathized_project_name ⇒ Object (readonly)
Returns the value of attribute pathized_project_name.
4 5 6 |
# File 'lib/rstack/generator.rb', line 4 def pathized_project_name @pathized_project_name end |
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
4 5 6 |
# File 'lib/rstack/generator.rb', line 4 def project_name @project_name end |
#templates_path ⇒ Object (readonly)
Returns the value of attribute templates_path.
4 5 6 |
# File 'lib/rstack/generator.rb', line 4 def templates_path @templates_path end |
Instance Method Details
#author ⇒ Object
54 55 56 |
# File 'lib/rstack/generator.rb', line 54 def ENV['USERNAME'] || ENV['USER'] || '[ENTER YOUR USERNAME]' end |
#create_directories ⇒ Object
39 40 41 42 43 44 |
# File 'lib/rstack/generator.rb', line 39 def create_directories paths.values.each do |path| puts "creating #{path}" path.mkpath end end |
#move_template(template_name, destination_path) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/rstack/generator.rb', line 46 def move_template(template_name, destination_path) puts "moving #{template_name} to #{destination_path}" contents = File.read(templates_path + template_name) File.open(destination_path, 'w') do |f| f << eval('"' + contents + '"') end end |
#paths ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/rstack/generator.rb', line 19 def paths { :bin => path.join('bin'), :lib => path.join('lib'), :main => path.join('lib', @main_path), :project => path.join('lib', @pathized_project_name), :spec => path.join('spec') } end |
#run ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/rstack/generator.rb', line 29 def run create_directories move_template "Rakefile", path.join('Rakefile') move_template "README.txt", path.join('README.txt') move_template "cruise_config.rb", path.join('cruise_config.rb') move_template "main.rb", paths[:main].join(@main) move_template "version.rb", paths[:project].join('version.rb') move_template "spec_helper.rb", paths[:spec].join('spec_helper.rb') end |