Class: Sinator::Generator
- Inherits:
-
Object
- Object
- Sinator::Generator
- Defined in:
- lib/sinator/generator.rb
Instance Attribute Summary collapse
-
#app_class_name ⇒ Object
Returns the value of attribute app_class_name.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#destination ⇒ Object
Returns the value of attribute destination.
Instance Method Summary collapse
- #generate_app ⇒ Object
- #generate_bundle_config ⇒ Object
- #generate_gemfile ⇒ Object
- #generate_puma_config ⇒ Object
- #generate_rakefile ⇒ Object
-
#initialize(app_name, options = {}) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(app_name, options = {}) ⇒ Generator
Returns a new instance of Generator.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sinator/generator.rb', line 11 def initialize(app_name, ={}) @app_name = app_name @app_class_name = app_name.split("_").map{|s| s.capitalize }.join("") destination = [:destination] ? "#{[:destination]}/#{@app_name}" : @app_name @with_database = [:with_database] unless File.directory?(destination) FileUtils.mkdir_p(destination) end @destination = File.(destination) end |
Instance Attribute Details
#app_class_name ⇒ Object
Returns the value of attribute app_class_name.
9 10 11 |
# File 'lib/sinator/generator.rb', line 9 def app_class_name @app_class_name end |
#app_name ⇒ Object
Returns the value of attribute app_name.
9 10 11 |
# File 'lib/sinator/generator.rb', line 9 def app_name @app_name end |
#destination ⇒ Object
Returns the value of attribute destination.
9 10 11 |
# File 'lib/sinator/generator.rb', line 9 def destination @destination end |
Instance Method Details
#generate_app ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sinator/generator.rb', line 68 def generate_app copy_templates app = File.read File.("../templates/app.erb", __FILE__) erb = ERB.new app, 0, '-' File.open "#{@destination}/#{@app_name}.rb", "w" do |f| f.write erb.result(binding) end route = File.read File.("../templates/app/routes/home.erb", __FILE__) erb = ERB.new route, 0, '-' File.open "#{@destination}/app/routes/home.rb", "w" do |f| f.write erb.result(binding) end FileUtils.rm "#{@destination}/app/routes/home.erb" end |
#generate_bundle_config ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/sinator/generator.rb', line 43 def generate_bundle_config config_ru = File.read File.("../templates/config.ru.erb", __FILE__) erb = ERB.new config_ru File.open "#{@destination}/config.ru", "w" do |f| f.write erb.result(binding) end end |
#generate_gemfile ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/sinator/generator.rb', line 34 def generate_gemfile gemfile = File.read File.("../templates/Gemfile.erb", __FILE__) erb = ERB.new gemfile, 0, '-' File.open "#{@destination}/Gemfile", "w" do |f| f.write erb.result(binding) end end |
#generate_puma_config ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sinator/generator.rb', line 52 def generate_puma_config puma_development = File.read File.("../templates/config/puma/development.erb", __FILE__) puma_production = File.read File.("../templates/config/puma/production.erb", __FILE__) erb = ERB.new puma_development, 0, '-' File.open "#{@destination}/config/puma/development.rb", "w" do |f| f.write erb.result(binding) end erb = ERB.new puma_production, 0, '-' File.open "#{@destination}/config/puma/production.rb", "w" do |f| f.write erb.result(binding) end end |
#generate_rakefile ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/sinator/generator.rb', line 25 def generate_rakefile gemfile = File.read File.("../templates/Rakefile.erb", __FILE__) erb = ERB.new gemfile, 0, '-' File.open "#{@destination}/Rakefile", "w" do |f| f.write erb.result(binding) end end |