Class: RspecScaffoldGenerator
- Inherits:
-
Rails::Generator::NamedBase
- Object
- Rails::Generator::NamedBase
- RspecScaffoldGenerator
- Defined in:
- lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_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_name ⇒ Object
readonly
Returns the value of attribute controller_name.
-
#controller_plural_name ⇒ Object
(also: #controller_table_name)
readonly
Returns the value of attribute controller_plural_name.
-
#controller_singular_name ⇒ Object
(also: #controller_file_name)
readonly
Returns the value of attribute controller_singular_name.
-
#default_file_extension ⇒ Object
readonly
Returns the value of attribute default_file_extension.
-
#resource_edit_path ⇒ Object
readonly
Returns the value of attribute resource_edit_path.
Instance Method Summary collapse
-
#initialize(runtime_args, runtime_options = {}) ⇒ RspecScaffoldGenerator
constructor
A new instance of RspecScaffoldGenerator.
- #manifest ⇒ Object
Constructor Details
#initialize(runtime_args, runtime_options = {}) ⇒ RspecScaffoldGenerator
Returns a new instance of RspecScaffoldGenerator.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 19 def initialize(runtime_args, = {}) super @controller_name = @name.pluralize 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 @default_file_extension = "html.erb" end |
Instance Attribute Details
#controller_class_name ⇒ Object (readonly)
Returns the value of attribute controller_class_name.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def controller_class_name @controller_class_name end |
#controller_class_nesting ⇒ Object (readonly)
Returns the value of attribute controller_class_nesting.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def controller_class_nesting @controller_class_nesting end |
#controller_class_nesting_depth ⇒ Object (readonly)
Returns the value of attribute controller_class_nesting_depth.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def controller_class_nesting_depth @controller_class_nesting_depth end |
#controller_class_path ⇒ Object (readonly)
Returns the value of attribute controller_class_path.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def controller_class_path @controller_class_path end |
#controller_file_path ⇒ Object (readonly)
Returns the value of attribute controller_file_path.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def controller_file_path @controller_file_path end |
#controller_name ⇒ Object (readonly)
Returns the value of attribute controller_name.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def controller_name @controller_name end |
#controller_plural_name ⇒ Object (readonly) Also known as: controller_table_name
Returns the value of attribute controller_plural_name.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def controller_plural_name @controller_plural_name end |
#controller_singular_name ⇒ Object (readonly) Also known as: controller_file_name
Returns the value of attribute controller_singular_name.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def controller_singular_name @controller_singular_name end |
#default_file_extension ⇒ Object (readonly)
Returns the value of attribute default_file_extension.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def default_file_extension @default_file_extension end |
#resource_edit_path ⇒ Object (readonly)
Returns the value of attribute resource_edit_path.
6 7 8 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 6 def resource_edit_path @resource_edit_path end |
Instance Method Details
#manifest ⇒ Object
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 36 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 spec 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('app/views/layouts', controller_class_path)) m.directory(File.join('public/stylesheets', class_path)) m.directory(File.join('spec/controllers', controller_class_path)) m.directory(File.join('spec/routing', controller_class_path)) m.directory(File.join('spec/models', class_path)) m.directory(File.join('spec/helpers', class_path)) m.directory File.join('spec/fixtures', class_path) m.directory File.join('spec/views', controller_class_path, controller_file_name) m.directory File.join('spec/integration', class_path) # Layout and stylesheet. m.template("scaffold:layout.html.erb", File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb")) m.template("scaffold:style.css", 'public/stylesheets/scaffold.css') # Controller spec, class, and helper. m.template 'rspec_scaffold:routing_spec.rb', File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb") m.template 'rspec_scaffold:controller_spec.rb', File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb") m.template "scaffold:controller.rb", File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb") m.template 'rspec_scaffold:helper_spec.rb', File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb") m.template "scaffold:helper.rb", File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb") for action in scaffold_views m.template( "scaffold:view_#{action}.#{@default_file_extension}", File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}") ) end # Model class, unit test, and fixtures. m.template 'model:model.rb', File.join('app/models', class_path, "#{file_name}.rb") m.template 'model:fixtures.yml', File.join('spec/fixtures', class_path, "#{table_name}.yml") m.template 'rspec_model:model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb") # View specs m.template "rspec_scaffold:edit_erb_spec.rb", File.join('spec/views', controller_class_path, controller_file_name, "edit.#{default_file_extension}_spec.rb") m.template "rspec_scaffold:index_erb_spec.rb", File.join('spec/views', controller_class_path, controller_file_name, "index.#{default_file_extension}_spec.rb") m.template "rspec_scaffold:new_erb_spec.rb", File.join('spec/views', controller_class_path, controller_file_name, "new.#{default_file_extension}_spec.rb") m.template "rspec_scaffold:show_erb_spec.rb", File.join('spec/views', controller_class_path, controller_file_name, "show.#{default_file_extension}_spec.rb") # Integration m.template 'integration_spec:integration_spec.rb', File.join('spec/integration', class_path, "#{table_name}_spec.rb") unless [:skip_migration] m.migration_template( 'model:migration.rb', 'db/migrate', :assigns => { :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}", :attributes => attributes }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" ) end m.route_resources controller_file_name end end |