Sha256: 5d29e588eec4607bcc9d9e72eb969288c7b40525b1f1f8d439774ec7da2625c5

Contents?: true

Size: 995 Bytes

Versions: 4

Compression:

Stored size: 995 Bytes

Contents

# frozen_string_literal: true

require 'rails/generators/base'

module LatoCore
  # CrudGenerator.
  class CrudGenerator < Rails::Generators::Base

    source_root File.expand_path('../templates', __FILE__)

    argument :model_name, type: :string, default: 'Crud'

    desc 'This function create a complete crud with Lato.'
    def create_crud
      set_utils_names

      run_lato_crud_controller_generator
      run_lato_crud_views_generator

      update_route
    end

    private

    def set_utils_names
      @model_name = model_name
      @singular_name = @model_name.underscore
      @plural_name = @singular_name.pluralize
      @controller_name = @plural_name.camelize
    end

    def run_lato_crud_controller_generator
      generate 'lato_core:crud_controller', model_name
    end

    def run_lato_crud_views_generator
      generate 'lato_core:crud_views', model_name
    end

    def update_route
      route "namespace :lato { resources :#{@plural_name} }"
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lato_core-2.2.2 lib/generators/lato_core/crud_generator.rb
lato_core-2.2.0 lib/generators/lato_core/crud_generator.rb
lato_core-2.1.4 lib/generators/lato_core/crud_generator.rb
lato_core-2.1.3 lib/generators/lato_core/crud_generator.rb