Sha256: 1f8c8057d134727ea1958435800c8bed254c15bc3fe8b562d6ddd6f4ec62e679

Contents?: true

Size: 764 Bytes

Versions: 3

Compression:

Stored size: 764 Bytes

Contents

class DynamicScaffoldGenerator < Rails::Generators::Base
  source_root File.expand_path('templates', __dir__)

  argument :path, type: 'string', required: true
  argument :model, type: 'string', required: false

  def init
    @namespases = path.split('/')
    @plural_model_name = @namespases.pop.camelize
    @class_scope = @namespases.map(&:camelize).join('::')
    @model_name = model ? model : @plural_model_name.singularize
    @model_name = @model_name.camelize
    @model = @model_name.constantize
  end

  def create_controllers
    template 'controller.erb', "app/controllers/#{path}_controller.rb"
  end

  def create_views
    %i[edit index new].each do |file|
      template "views/#{file}.erb", "app/views/#{path}/#{file}.html.erb"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dynamic_scaffold-0.1.4 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-0.1.3 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-0.1.2 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb