Class: Ingoweiss::ScaffoldGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Ingoweiss::ScaffoldGenerator
show all
- Includes:
- Rails::Generators::Migration, Rails::Generators::ResourceHelpers, ScopeHelpers
- Defined in:
- lib/generators/ingoweiss/scaffold/scaffold_generator.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#instance_variable_scope, #scope, #scope_prefix, #scoped?, #scoped_controller_class_name, #scoped_controller_plural_name, #singleton?, #unscoped?
Class Method Details
.source_root ⇒ Object
18
19
20
|
# File 'lib/generators/ingoweiss/scaffold/scaffold_generator.rb', line 18
def self.source_root
@source_root ||= File.expand_path('../../templates', __FILE__)
end
|
Instance Method Details
#add_routes ⇒ Object
22
23
24
25
|
# File 'lib/generators/ingoweiss/scaffold/scaffold_generator.rb', line 22
def add_routes
return if options[:skip_route]
route "resource#{'s' unless options[:singleton]} :#{options[:singleton] ? singular_name : plural_name}"
end
|
#generate_model ⇒ Object
27
28
29
30
31
|
# File 'lib/generators/ingoweiss/scaffold/scaffold_generator.rb', line 27
def generate_model
arguments = [singular_name] + attributes.collect{ |a| [a.name, a.type].join(':') }
arguments << "#{scope.last.singularize}_id:integer" if scope.any?
invoke :model, arguments
end
|
#inject_associations ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/generators/ingoweiss/scaffold/scaffold_generator.rb', line 33
def inject_associations
return if scope.empty?
parent = scope.last.singularize
inject_into_file("app/models/#{parent}.rb", :after => /< ActiveRecord::Base\n/) do
options[:singleton] ? " has_one :#{singular_name}\n" : " has_many :#{plural_name}\n"
end
inject_into_file("app/models/#{singular_name}.rb", :after => /< ActiveRecord::Base\n/) do
" belongs_to :#{parent}\n"
end
end
|