Class: ResourcefulScaffoldGenerator
- Inherits:
-
Rails::Generator::NamedBase
- Object
- Rails::Generator::NamedBase
- ResourcefulScaffoldGenerator
- Defined in:
- lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb
Instance Attribute Summary collapse
-
#controller_class_name ⇒ Object
readonly
Returns the value of attribute controller_class_name.
-
#controller_class_nesting ⇒ Object
readonly
Returns the value of attribute controller_class_nesting.
-
#controller_class_nesting_depth ⇒ Object
readonly
Returns the value of attribute controller_class_nesting_depth.
-
#controller_class_path ⇒ Object
readonly
Returns the value of attribute controller_class_path.
-
#controller_file_path ⇒ Object
readonly
Returns the value of attribute controller_file_path.
-
#controller_plural_name ⇒ Object
(also: #controller_table_name)
readonly
Returns the value of attribute controller_plural_name.
-
#controller_underscore_name ⇒ Object
(also: #controller_file_name)
readonly
Returns the value of attribute controller_underscore_name.
Instance Method Summary collapse
-
#initialize(runtime_args, runtime_options = {}) ⇒ ResourcefulScaffoldGenerator
constructor
A new instance of ResourcefulScaffoldGenerator.
- #manifest ⇒ Object
Constructor Details
#initialize(runtime_args, runtime_options = {}) ⇒ ResourcefulScaffoldGenerator
Returns a new instance of ResourcefulScaffoldGenerator.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 12 def initialize(runtime_args, = {}) super base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@name.pluralize) @controller_class_name_without_nesting, @controller_underscore_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 |
Instance Attribute Details
#controller_class_name ⇒ Object (readonly)
Returns the value of attribute controller_class_name.
2 3 4 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 2 def controller_class_name @controller_class_name end |
#controller_class_nesting ⇒ Object (readonly)
Returns the value of attribute controller_class_nesting.
2 3 4 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 2 def controller_class_nesting @controller_class_nesting end |
#controller_class_nesting_depth ⇒ Object (readonly)
Returns the value of attribute controller_class_nesting_depth.
2 3 4 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 2 def controller_class_nesting_depth @controller_class_nesting_depth end |
#controller_class_path ⇒ Object (readonly)
Returns the value of attribute controller_class_path.
2 3 4 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 2 def controller_class_path @controller_class_path end |
#controller_file_path ⇒ Object (readonly)
Returns the value of attribute controller_file_path.
2 3 4 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 2 def controller_file_path @controller_file_path end |
#controller_plural_name ⇒ Object (readonly) Also known as: controller_table_name
Returns the value of attribute controller_plural_name.
2 3 4 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 2 def controller_plural_name @controller_plural_name end |
#controller_underscore_name ⇒ Object (readonly) Also known as: controller_file_name
Returns the value of attribute controller_underscore_name.
2 3 4 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 2 def controller_underscore_name @controller_underscore_name end |
Instance Method Details
#manifest ⇒ Object
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 65 66 67 68 69 70 71 72 |
# File 'lib/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb', line 25 def manifest record do |m| # Check for class naming collisions. m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper") m.class_collisions(class_path, "#{class_name}") # Controller, helper, views, and test directories. m.directory(File.join('app/models', class_path)) m.directory(File.join('app/controllers', controller_class_path)) m.directory(File.join('app/helpers', controller_class_path)) m.directory(File.join('app/views', controller_class_path, controller_file_name)) m.directory(File.join('test/functional', controller_class_path)) m.directory(File.join('test/unit', class_path)) m.directory(File.join('test/fixtures', class_path)) # Views for action in scaffold_views m.template("view_#{action}.haml", File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.haml")) end m.template('view_partial.haml', File.join('app/views', controller_class_path, controller_file_name, "_#{singular_name}.html.haml")) # Helper m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")) # Model m.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb")) unless [:skip_migration] m.migration_template('migration.rb', 'db/migrate', :assigns => { :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}", :attributes => attributes }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}") end # Controller m.template('controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")) # Tests m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")) m.template('unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")) m.template('fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")) # Route m.route_resources controller_file_name end end |