Class: ActiveScaffoldGenerator

Inherits:
Rails::Generator::NamedBase
  • Object
show all
Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ActiveScaffoldGenerator.



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 214

def initialize(runtime_args, runtime_options = {})
  super

  # Take controller name from the next argument.  Default to the pluralized model name.
  @controller_name = args.shift
  @controller_name ||= ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name

  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

Instance Attribute Details

#controller_class_nameObject (readonly)

Returns the value of attribute controller_class_name.



203
204
205
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 203

def controller_class_name
  @controller_class_name
end

#controller_class_nestingObject (readonly)

Returns the value of attribute controller_class_nesting.



203
204
205
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 203

def controller_class_nesting
  @controller_class_nesting
end

#controller_class_nesting_depthObject (readonly)

Returns the value of attribute controller_class_nesting_depth.



203
204
205
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 203

def controller_class_nesting_depth
  @controller_class_nesting_depth
end

#controller_class_pathObject (readonly)

Returns the value of attribute controller_class_path.



203
204
205
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 203

def controller_class_path
  @controller_class_path
end

#controller_file_pathObject (readonly)

Returns the value of attribute controller_file_path.



203
204
205
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 203

def controller_file_path
  @controller_file_path
end

#controller_nameObject (readonly)

Returns the value of attribute controller_name.



203
204
205
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 203

def controller_name
  @controller_name
end

#controller_plural_nameObject (readonly) Also known as: controller_table_name

Returns the value of attribute controller_plural_name.



203
204
205
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 203

def controller_plural_name
  @controller_plural_name
end

#controller_singular_nameObject (readonly) Also known as: controller_file_name

Returns the value of attribute controller_singular_name.



203
204
205
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 203

def controller_singular_name
  @controller_singular_name
end

Instance Method Details

#manifestObject

def controller_file_path

"/" + base_controller_file_path

end



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/generators/active_scaffold/active_scaffold_generator.rb', line 235

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_class_name}Helper"

    # Controller, helper, views, and test directories.

    # Model, controller, helper, views, and test directories.
    m.directory File.join('app/models', class_path)
    m.directory File.join('test/unit', class_path)
    # I use factories
    # m.directory File.join('test/fixtures', 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('test/functional', controller_class_path)

    # Unit test, and fixtures.
    # m.template 'unit_test.rb',  File.join('test/unit', "#{singular_name}_test.rb")
    # I use factories
    # m.template 'fixtures.yml',  File.join('test/fixtures', "#{singular_name}.yml")

    m.complex_template 'model.rb',
      File.join('app/models', "#{singular_name}.rb"),
      :insert => 'model_scaffolding.rhtml',
      :sandbox => lambda { create_sandbox }

    m.complex_template('form.rhtml',
      File.join('app/views',
                controller_class_path,
                controller_file_name,
                '_form.rhtml'),
      :insert => 'form_scaffolding.rhtml',
      :sandbox => lambda { create_sandbox },
      :begin_mark => 'form',
      :end_mark => 'eoform',
      :mark_id => singular_name) if less_dry_partial?

    m.complex_template('show.rhtml',
      File.join('app/views',
                controller_class_path,
                controller_file_name,
                '_show.rhtml'),
      :insert => 'show_scaffolding.rhtml',
      :sandbox => lambda { create_sandbox },
      :begin_mark => 'show',
      :end_mark => 'eoshow',
      :mark_id => singular_name) if less_dry_partial?

    # Controller class, functional test, helper, and views.
    # m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
    controller_template_name = 'controller_methods.rb'
    m.complex_template controller_template_name,
      File.join('app/controllers',
              controller_class_path,
              "#{controller_file_name}_controller.rb"),
      :insert => 'controller_scaffolding.rhtml',
      :sandbox => lambda { create_sandbox }
    m.template 'helper.rb',
      File.join('app/helpers',
                controller_class_path,
                "#{controller_file_name}_helper.rb")  

  end
end