1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Add namespace to aasm generator

- fix #328
This commit is contained in:
Anil 2016-02-21 17:00:37 +05:30
parent 82f592a1ed
commit 24f757b130
3 changed files with 8 additions and 9 deletions

View file

@ -3,8 +3,7 @@ require 'rails/generators/named_base'
module AASM
module Generators
class AASMGenerator < Rails::Generators::NamedBase
source_root File.expand_path("../templates", __FILE__)
namespace "aasm"
argument :column_name, type: :string, default: 'aasm_state'
desc "Generates a model with the given NAME (if one does not exist) with aasm " <<

View file

@ -5,7 +5,7 @@ module ActiveRecord
module Generators
class AASMGenerator < ActiveRecord::Generators::Base
include AASM::Generators::OrmHelpers
namespace "active_record:aasm"
argument :column_name, type: :string, default: 'aasm_state'
source_root File.expand_path("../templates", __FILE__)
@ -16,11 +16,11 @@ module ActiveRecord
else
migration_template "migration.rb", "db/migrate/aasm_create_#{table_name}.rb"
end
end
end
def generate_model
invoke "active_record:model", [name], migration: false unless model_exists?
end
end
def inject_aasm_content
content = model_contents

View file

@ -5,20 +5,20 @@ module Mongoid
module Generators
class AASMGenerator < Rails::Generators::NamedBase
include AASM::Generators::OrmHelpers
namespace "mongoid:aasm"
argument :column_name, type: :string, default: 'aasm_state'
def generate_model
invoke "mongoid:model", [name] unless model_exists?
end
end
def inject_aasm_content
inject_into_file model_path, model_contents, after: "include Mongoid::Document\n" if model_exists?
end
end
def inject_field_types
inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists?
end
end
def migration_data
" field :#{column_name}"