Sha256: 9196f14a9b3d822a8a9caefd8df26f4821f2b5ef3f777766acd998b6be907ee3

Contents?: true

Size: 746 Bytes

Versions: 2

Compression:

Stored size: 746 Bytes

Contents

# frozen_string_literal: true

require 'rails/generators'
require 'rails/generators/active_record/migration/migration_generator'

module Logux
  module Generators
    class ModelGenerator < ::ActiveRecord::Generators::Base # :nodoc:
      source_root File.expand_path('templates', __dir__)

      class_option :nullable,
                   type: :boolean,
                   optional: true,
                   desc: 'Define whether field should have not-null constraint'

      def generate_migration
        migration_template(
          'migration.rb.erb',
          "db/migrate/add_logux_fields_updated_at_to_#{plural_table_name}.rb"
        )
      end

      def nullable?
        options.fetch(:nullable, false)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logux_rails-0.2.0 lib/generators/logux/model/model_generator.rb
logux_rails-0.1.0 lib/generators/logux/model/model_generator.rb