Sha256: f316313ae672848d309538790228f9b719f001047fba08a625b6fecdaecb5c8f

Contents?: true

Size: 869 Bytes

Versions: 20

Compression:

Stored size: 869 Bytes

Contents

# frozen_string_literal: true

require_relative "../../lib/plutonium_generators"

module Pu
  module Res
    class ModelGenerator < PlutoniumGenerators::ModelGeneratorBase
      source_root File.expand_path("templates", __dir__)

      def run_create_module
        create_module_file if create_files?
      end

      def run_create_model
        model_class = class_name.safe_constantize
        if model_class.present? && !model_class.include?(Plutonium::Resource::Record)
          gsub_file File.join("app/models", class_path, "#{file_name}.rb"),
            "< ApplicationRecord",
            "< ResourceRecord"
        end

        create_model_file if create_files?
      end

      def run_create_migration
        create_migration_file if create_files?
      end

      private

      def create_files?
        attributes.present?
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
plutonium-0.14.1 lib/generators/pu/res/model/model_generator.rb
plutonium-0.14.0 lib/generators/pu/res/model/model_generator.rb
plutonium-0.13.3 lib/generators/pu/res/model/model_generator.rb
plutonium-0.13.2 lib/generators/pu/res/model/model_generator.rb
plutonium-0.13.1 lib/generators/pu/res/model/model_generator.rb
plutonium-0.13.0 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.14 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.13 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.12 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.11 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.10 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.9 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.8 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.7 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.5 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.4 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.3 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.2 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.1 lib/generators/pu/res/model/model_generator.rb
plutonium-0.12.0 lib/generators/pu/res/model/model_generator.rb