Class: ScaffoldGenerator

Inherits:
Genosaurus
  • Object
show all
Defined in:
lib/mack-orm/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_generateObject

:nodoc:



17
18
19
20
21
# File 'lib/mack-orm/scaffold_generator/scaffold_generator.rb', line 17

def after_generate # :nodoc:
  ModelGenerator.run(@options)
  ControllerHelperGenerator.run(@options)
  update_routes_file
end

#setupObject

:nodoc:



9
10
11
12
13
14
15
# File 'lib/mack-orm/scaffold_generator/scaffold_generator.rb', line 9

def setup # :nodoc:
  @name_singular = param(:name).singular.underscore
  @name_plural = @name_singular.plural.underscore
  @name_singular_camel = @name_singular.camelcase
  @name_plural_camel = @name_plural.camelcase
  @test_framework = configatron.mack.testing_framework
end

#showable_columnsObject



23
24
25
26
# File 'lib/mack-orm/scaffold_generator/scaffold_generator.rb', line 23

def showable_columns
  cols = columns.reject {|c| c.column_name.downcase.match(/password/)}
  cols
end

#update_routes_fileObject

:nodoc:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mack-orm/scaffold_generator/scaffold_generator.rb', line 28

def update_routes_file # :nodoc:
  # update routes.rb
  routes = Mack::Paths.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