Class: RailsGae
- Inherits:
-
Object
- Object
- RailsGae
- Defined in:
- lib/rails_gae.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
(also: #destination_folder)
readonly
Returns the value of attribute app_name.
-
#rails_version ⇒ Object
readonly
Returns the value of attribute rails_version.
Instance Method Summary collapse
- #copy_files ⇒ Object
- #create_rails_project ⇒ Object
- #files_dir ⇒ Object
- #generate_templates ⇒ Object
-
#initialize(app_name) ⇒ RailsGae
constructor
A new instance of RailsGae.
- #run! ⇒ Object
- #templates ⇒ Object
- #templates_dir ⇒ Object
Constructor Details
#initialize(app_name) ⇒ RailsGae
Returns a new instance of RailsGae.
10 11 12 13 14 |
# File 'lib/rails_gae.rb', line 10 def initialize(app_name) rails_version = '2.3.11' @app_name = app_name @rails_version = rails_version end |
Instance Attribute Details
#app_name ⇒ Object (readonly) Also known as: destination_folder
Returns the value of attribute app_name.
6 7 8 |
# File 'lib/rails_gae.rb', line 6 def app_name @app_name end |
#rails_version ⇒ Object (readonly)
Returns the value of attribute rails_version.
6 7 8 |
# File 'lib/rails_gae.rb', line 6 def rails_version @rails_version end |
Instance Method Details
#copy_files ⇒ Object
26 27 28 |
# File 'lib/rails_gae.rb', line 26 def copy_files FileUtils.cp_r(File.join(files_dir, '.'), destination_folder) end |
#create_rails_project ⇒ Object
22 23 24 |
# File 'lib/rails_gae.rb', line 22 def create_rails_project puts `rails _#{rails_version}_ #{app_name}` end |
#files_dir ⇒ Object
38 39 40 |
# File 'lib/rails_gae.rb', line 38 def files_dir File.join(File.dirname(__FILE__), 'generator', 'files') end |
#generate_templates ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rails_gae.rb', line 30 def generate_templates FileUtils.cp_r(File.join(templates_dir, '.'), destination_folder) templates.each do |template| file = ERB.new(File.open(template).read) File.open(template, 'w+').write(file.result(binding)) end end |
#run! ⇒ Object
16 17 18 19 20 |
# File 'lib/rails_gae.rb', line 16 def run! create_rails_project copy_files generate_templates end |
#templates ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/rails_gae.rb', line 46 def templates templates = Dir.glob(File.join(templates_dir, '**', '*')).select{ |f| File.file?(f) } templates.map do |template_path| relative_path = template_path.sub(templates_dir, '') File.join(destination_folder, relative_path) end end |
#templates_dir ⇒ Object
42 43 44 |
# File 'lib/rails_gae.rb', line 42 def templates_dir File.join(File.dirname(__FILE__), 'generator', 'templates') end |