Sha256: 2c06576c18f4e2ac4ac9987cd57b147f8922fb7de609464302248b8f51dbdfdd

Contents?: true

Size: 759 Bytes

Versions: 3

Compression:

Stored size: 759 Bytes

Contents

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

module Mongoid
  module Generators
    class AASMGenerator < Rails::Generators::NamedBase
      include AASM::Generators::OrmHelpers

      argument :column_name, type: :string, default: 'aasm_state'

      def generate_model
        invoke "mongoid:model", [name] unless model_exists?
      end 

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aasm-4.8.0 lib/generators/mongoid/aasm_generator.rb
aasm-4.7.0 lib/generators/mongoid/aasm_generator.rb
aasm-4.6.0 lib/generators/mongoid/aasm_generator.rb