Sha256: bc92314d09e65ecaf89db5abf9cbf950d50e957a7215f34679ac89d67fd8bc27

Contents?: true

Size: 892 Bytes

Versions: 35

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

require 'rails/generators'
require 'rails/generators/named_base'
require 'rails/generators/base'
require 'active_support'
require 'active_support/core_ext/string/inflections'

module Ibrain
  module Core
    class ModelGenerator < Rails::Generators::Base
      desc "Create a model by name"
      source_root File.expand_path('templates', __dir__)

      argument :name, type: :string

      def initialize(args, *options) # :nodoc:
        # Unfreeze name in case it's given as a frozen string
        args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen?
        super

        assign_names!(name)
      end

      attr_reader :file_name

      def create_model_file
        template "model.erb", "app/models/#{file_name}.rb"
      end

      private

      def assign_names!(name)
        @file_name = name.underscore
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
ibrain-core-0.5.15 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.13 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.12 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.10 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.9 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.8 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.7 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.6 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.5 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.4 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.3 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.2 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.1 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.5.0 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.4.9 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.4.8 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.4.7 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.4.5 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.4.4 lib/generators/ibrain/core/model_generator.rb
ibrain-core-0.4.3 lib/generators/ibrain/core/model_generator.rb