Class: ScaffoldGenerator
- Inherits:
-
Genosaurus
- Object
- Genosaurus
- ScaffoldGenerator
- Defined in:
- lib/generators/scaffold_generator/scaffold_generator.rb
Overview
Generates scaffold for Mack applications.
Example:
rake generate:scaffold name=post
Instance Method Summary collapse
Instance Method Details
#after_generate ⇒ Object
16 17 18 19 20 21 |
# File 'lib/generators/scaffold_generator/scaffold_generator.rb', line 16 def after_generate if app_config.orm ModelGenerator.run(@options) end update_routes_file end |
#setup ⇒ Object
9 10 11 12 13 14 |
# File 'lib/generators/scaffold_generator/scaffold_generator.rb', line 9 def setup @name_singular = param(:name).singular.underscore @name_plural = param(:name).plural.underscore @name_singular_camel = @name_singular.camelcase @name_plural_camel = @name_plural.camelcase end |
#update_routes_file ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/scaffold_generator/scaffold_generator.rb', line 23 def update_routes_file # update routes.rb routes = File.join(MACK_CONFIG, "routes.rb") rf = File.open(routes).read unless rf.match(".resource :#{@name_plural}") puts "Updating routes.rb" nrf = "" rf.each do |line| if line.match("Mack::Routes.build") x = line.match(/\|(.+)\|/).captures line << "\n #{x}.resource :#{@name_plural} # Added by rake generate:scaffold name=#{param(:name)}\n" end nrf << line end File.open(routes, "w") do |f| f.puts nrf end end end |