Class: RailsGae

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_gae.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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_versionObject (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_filesObject



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_projectObject



22
23
24
# File 'lib/rails_gae.rb', line 22

def create_rails_project
  puts `rails _#{rails_version}_ #{app_name}`
end

#files_dirObject



38
39
40
# File 'lib/rails_gae.rb', line 38

def files_dir
  File.join(File.dirname(__FILE__), 'generator', 'files')
end

#generate_templatesObject



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

#templatesObject



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_dirObject



42
43
44
# File 'lib/rails_gae.rb', line 42

def templates_dir
  File.join(File.dirname(__FILE__), 'generator', 'templates')
end