Class: ExtensionGenerator

Inherits:
Rails::Generator::NamedBase
  • Object
show all
Defined in:
lib/generators/extension/extension_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ ExtensionGenerator

Returns a new instance of ExtensionGenerator.



6
7
8
9
10
# File 'lib/generators/extension/extension_generator.rb', line 6

def initialize(runtime_args, runtime_options = {})
  super
  @extension_file_name = "#{file_name}_extension"
  @extension_path = "vendor/extensions/#{file_name}"
end

Instance Attribute Details

#extension_file_nameObject (readonly)

Returns the value of attribute extension_file_name.



4
5
6
# File 'lib/generators/extension/extension_generator.rb', line 4

def extension_file_name
  @extension_file_name
end

#extension_pathObject (readonly)

Returns the value of attribute extension_path.



4
5
6
# File 'lib/generators/extension/extension_generator.rb', line 4

def extension_path
  @extension_path
end

Instance Method Details

#add_options!(opt) ⇒ Object



58
59
60
61
62
63
# File 'lib/generators/extension/extension_generator.rb', line 58

def add_options!(opt)
  opt.separator ''
  opt.separator 'Options:'
  opt.on("--with-test-unit",
         "Use Test::Unit for this extension instead of RSpec") { |v| options[:with_test_unit] = v }
end

#class_nameObject



50
51
52
# File 'lib/generators/extension/extension_generator.rb', line 50

def class_name
  super.to_name.gsub(' ', '') + 'Extension'
end

#extension_nameObject



54
55
56
# File 'lib/generators/extension/extension_generator.rb', line 54

def extension_name
  class_name.to_name('Extension')
end

#manifestObject



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
# File 'lib/generators/extension/extension_generator.rb', line 12

def manifest
  record do |m|
    m.directory "#{extension_path}/app/controllers"
    m.directory "#{extension_path}/app/helpers"
    m.directory "#{extension_path}/app/models"
    m.directory "#{extension_path}/app/views"
    m.directory "#{extension_path}/db/migrate"
    m.directory "#{extension_path}/db/sample"
    m.directory "#{extension_path}/lib/tasks"
    m.directory "#{extension_path}/config/initializers"
    m.directory "#{extension_path}/public"

    m.template 'README.markdown',              "#{extension_path}/README.markdown"
    m.template 'extension.rb',        "#{extension_path}/#{extension_file_name}.rb"
    m.template 'tasks.rake',          "#{extension_path}/lib/tasks/#{extension_file_name}_tasks.rake"
    m.template 'routes.rb',          "#{extension_path}/config/routes.rb"

    if options[:with_test_unit]
      m.directory "#{extension_path}/test/fixtures"
      m.directory "#{extension_path}/test/functional"
      m.directory "#{extension_path}/test/unit"

      m.template 'Rakefile',            "#{extension_path}/Rakefile"
      m.template 'test_helper.rb',      "#{extension_path}/test/test_helper.rb"
      m.template 'functional_test.rb',  "#{extension_path}/test/functional/#{extension_file_name}_test.rb"
    else
      m.directory "#{extension_path}/spec/controllers"
      m.directory "#{extension_path}/spec/models"
      m.directory "#{extension_path}/spec/views"
      m.directory "#{extension_path}/spec/helpers"

      m.template 'RSpecRakefile',       "#{extension_path}/Rakefile"
      m.template 'spec_helper.rb',      "#{extension_path}/spec/spec_helper.rb"
      m.file     'spec.opts',           "#{extension_path}/spec/spec.opts"
    end
  end
end