Sha256: c6b8764457735852393cb9853034933551a089cf0c150eda7a431a7ab5ca5995

Contents?: true

Size: 768 Bytes

Versions: 2

Compression:

Stored size: 768 Bytes

Contents

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

  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

2 entries across 2 versions & 1 rubygems

Version Path
dynamic_scaffold-0.1.1 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-0.1.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb