public
Rubygem
Description: Gruff graphing library for Ruby
Homepage: http://gruff.rubyforge.org
Clone URL: git://github.com/topfunky/gruff.git
Search Repo:
topfunky (author)
Thu Mar 13 09:03:49 -0700 2008
commit  75c59127f7ed8b7d20b8cc8c930347e7ecfe092a
tree    62394d73f7649b791e554b05f4d1c1281fbfe766
parent  454623165c3321268facd9461d33d4b5940c6328
gruff / rails_generators / gruff / gruff_generator.rb
100644 64 lines (51 sloc) 2.494 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class GruffGenerator < Rails::Generator::NamedBase
 
  attr_reader :controller_name,
                :controller_class_path,
                :controller_file_path,
                :controller_class_nesting,
                :controller_class_nesting_depth,
                :controller_class_name,
                :controller_singular_name,
                :controller_plural_name,
                :parent_folder_for_require
  alias_method :controller_file_name, :controller_singular_name
  alias_method :controller_table_name, :controller_plural_name
 
  def initialize(runtime_args, runtime_options = {})
    super
 
    # Take controller name from the next argument.
    @controller_name = runtime_args.shift
 
    base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
    @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
 
    if @controller_class_nesting.empty?
      @controller_class_name = @controller_class_name_without_nesting
    else
      @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
    end
  end
 
  def manifest
    record do |m|
      # Check for class naming collisions.
      m.class_collisions controller_class_path, "#{controller_class_name}Controller",
                                                "#{controller_class_name}ControllerTest"
 
      # Controller, helper, views, and test directories.
      m.directory File.join('app/controllers', controller_class_path)
      m.directory File.join('test/functional', controller_class_path)
 
      m.template 'controller.rb',
                  File.join('app/controllers',
                            controller_class_path,
                            "#{controller_file_name}_controller.rb")
 
      # For some reason this doesn't take effect if done in initialize()
      @parent_folder_for_require = @controller_class_path.join('/').gsub(%r%app/controllers/?%, '')
      @parent_folder_for_require += @parent_folder_for_require.blank? ? '' : '/'
 
      m.template 'functional_test.rb',
                  File.join('test/functional',
                            controller_class_path,
                            "#{controller_file_name}_controller_test.rb")
 
    end
  end
 
  protected
    # Override with your own usage banner.
    def banner
      "Usage: #{$0} gruff ControllerName"
    end
end