Sha256: e56a116303c48f5c558508a92f6006edd767ea15263e9aabddc07a377ea7b875

Contents?: true

Size: 820 Bytes

Versions: 16

Compression:

Stored size: 820 Bytes

Contents

require 'rails/generators/named_base'
require 'generators/aasm/orm_helpers'

module NoBrainer
  module Generators
    class AASMGenerator < Rails::Generators::NamedBase
      include AASM::Generators::OrmHelpers
      namespace 'nobrainer:aasm'
      argument :column_name, type: :string, default: 'aasm_state'

      def generate_model
        invoke 'nobrainer:model', [name] unless model_exists?
      end

      def inject_aasm_content
        inject_into_file model_path, model_contents, after: "include NoBrainer::Document::Timestamps\n" if model_exists?
      end

      def inject_field_types
        inject_into_file model_path, migration_data, after: "include NoBrainer::Document::Timestamps\n" if model_exists?
      end

      def migration_data
        "  field :#{column_name}"
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
aasm-5.5.0 lib/generators/nobrainer/aasm_generator.rb
aasm-5.4.0 lib/generators/nobrainer/aasm_generator.rb
aasm-5.3.1 lib/generators/nobrainer/aasm_generator.rb
aasm-5.3.0 lib/generators/nobrainer/aasm_generator.rb
aasm-5.2.0 lib/generators/nobrainer/aasm_generator.rb
aasm-5.1.1 lib/generators/nobrainer/aasm_generator.rb
aasm-5.1.0 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.8 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.7 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.6 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.5 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.4 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.3 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.2 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.1 lib/generators/nobrainer/aasm_generator.rb
aasm-5.0.0 lib/generators/nobrainer/aasm_generator.rb